loop with fzero

2 ビュー (過去 30 日間)
Joon Jeon
Joon Jeon 2012 年 3 月 20 日
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?

採用された回答

Alexander
Alexander 2012 年 3 月 20 日
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 件のコメント
Joon Jeon
Joon Jeon 2012 年 3 月 20 日
Thanks, I will try!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by