loop with fzero

2 Ansichten (letzte 30 Tage)
Joon Jeon
Joon Jeon am 20 Mär. 2012
My goal is to derive x from such equation as
for i=1:9
z(i)=fzero(@(x)gamma/(R-(1+phi(1)*x)*(1+phi(2)))-tauA2(i)-((1+alpha*beta)/beta*(gamma/x-tauA1(i))),800)
end
Here, every alphabets and matrice are 'number's. And tauA1 and 2 is [9*1] for each.
Running it, however, keeps resulting in errors saying ??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> fzero at 333 elseif ~isfinite(fx) ~isreal(fx)
How can I get matrix x with 9*1 out of fzero?

Akzeptierte Antwort

Alexander
Alexander am 20 Mär. 2012
This works for me, if I set all variables to numbers:
tauA1 = zeros(9, 1); tauA2 = zeros(9, 1); alpha=1; beta=2; gamma=3; phi=[4,5]; R=6;
z = zeros(9, 1);
for i=1:9
z(i)=fzero(@(x)gamma/(R-(1+phi(1)*x)*(1+phi(2)))-tauA2(i)-((1+alpha*beta)/beta*(gamma/x-tauA1(i))),800);
end
Do you have any variables set to sym objects? If you want to use the algebraic solver, you need to call solve, like here:
syms x;
solve(gamma/(R-(1+phi(1)*x)*(1+phi(2)))-tauA2(i)-((1+alpha*beta)/beta*(gamma/x-tauA1(i))), x)
  1 Kommentar
Joon Jeon
Joon Jeon am 20 Mär. 2012
Thanks, I will try!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by