vectorizing solution using fzero
7 ビュー (過去 30 日間)
古いコメントを表示
i have equations of the form f(x,X)=0; where X is a column vector of size N. i can solve using for example
f = @(xx) ( f(xx, X))
for i = 1:N
sol(i) = fzero( f(X(i)), [ 0 , 1000])
end
How I would like to eliminate the for loop. Is there a way? I would like something like sol = fzero(f(X), [0,1000]), however it gives an error if I try this. Thanks in advance.
0 件のコメント
採用された回答
Matt J
2017 年 10 月 5 日
編集済み: Matt J
2017 年 10 月 5 日
Ok. Can I use fsolve to vectorize? My guess based on your answer is that I can not use fsolve either.
You could use fsolve to vectorize, but my feeling is that it is better not to, because this will increase the dimension of the problem and potentially slow convergence.
My recommendation would be to use parfor to parallelize the fzero calls. If the sol(i) are expected to change gradually with i, an alternative way to accelerate things would be to use sol(i-1) as your initial guess, as in,
init=[0,1000];
for i = 1:N
sol(i) = fzero( @(xx) f(xx, X(i)), init);
init=sol(i);
end
0 件のコメント
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!