loop with fzero

2 visualizaciones (últimos 30 días)
Joon Jeon
Joon Jeon el 20 de Mzo. de 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?

Respuesta aceptada

Alexander
Alexander el 20 de Mzo. de 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 comentario
Joon Jeon
Joon Jeon el 20 de Mzo. de 2012
Thanks, I will try!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by