loop with fzero

2 vues (au cours des 30 derniers jours)
Joon Jeon
Joon Jeon le 20 Mar 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?

Réponse acceptée

Alexander
Alexander le 20 Mar 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 commentaire
Joon Jeon
Joon Jeon le 20 Mar 2012
Thanks, I will try!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by