开发者

fsolve for solution != 0

开发者 https://www.devze.com 2023-01-16 00:51 出处:网络
I want to solve an equation for a different value in each cycle of a for loop.I usually include the value that I am solving 开发者_JS百科for in the m-file function but I can\'t change the m file at ea

I want to solve an equation for a different value in each cycle of a for loop. I usually include the value that I am solving 开发者_JS百科for in the m-file function but I can't change the m file at each cycle in the for loop. Is there a way to solve the use fsolve but for a value !=0.


You can use an anonymous function. So if your paramterised function is:

function y = f(x, c)
...
end

then you can iterate over different parameters thus:

for c = 0:10
    fsolve(@(x)f(x,c), x0);
end

(Untested)

0

精彩评论

暂无评论...
验证码 换一张
取 消