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 CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by