loop intial guesses in fsolve
Show older comments
I am trying to solve some equations by using solve.
Actually I did it. But this time, I am trying to vary some parameters.
Let's say I have one parameters which is 1:1:9.
And I code it like,
a=1:1:9
for i=1:9
y=@(x) x*exp(a(i))-x/2;
f=@(x) a(i)*x^2+1/2*y(x)-300;
x0=200:-10:110;
p(i)=fsolve(f, x0(i));
end
But it gives me an error message that index matrix is not matching. Is it possible to loop initial guesses in fsolve? (above coding is just an example.)
Since I only use one set of initial guesses in my real model, fsolve keep giving me the same solution.
Accepted Answer
More Answers (1)
Sean de Wolski
on 3 Apr 2012
Copying and pasting what you have above works for me. What do you have for fsolve? IS it being shadowed perhaps?
which -all fsolve
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!