solving non linear equation

조회 수: 2 (최근 30일)
RAFFAELE CANTERI
RAFFAELE CANTERI 2020년 10월 12일
댓글: Star Strider 2020년 10월 13일
how can i return a vector as a solution?
I want back a number of roots equal to the number of values ​​of t
syms S
>> myfun = @(S,t) 0.17*((S/10.8)+(S/21.6*sqrt(1+16*((S/5.4)^2))+((1/16)*log((4*S/5.4)+sqrt(1+(16*(S/5.4)^2))))))- t
>> t = linspace(0,2.6,10)
>> fun = @(S) myfun(S,t)
S = fzero(fun,0.03)
The program return this error:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 327)
elseif ~isfinite(fx) || ~isreal(fx)

채택된 답변

Star Strider
Star Strider 2020년 10월 12일
First:
vv = vectorize('0.17*((S/10.8)+(S/21.6*sqrt(1+16*((S/5.4)^2))+((1/16)*log((4*S/5.4)+sqrt(1+(16*(S/5.4)^2))))))- t')
then copy the result (between the single quotes) to the body of ‘myfun’.
After that (I have already done and copied the vectorized result):
myfun = @(S,t) 0.17.*((S./10.8)+(S./21.6.*sqrt(1+16.*((S./5.4).^2))+((1./16).*log((4.*S./5.4)+sqrt(1+(16.*(S./5.4).^2))))))- t;
t = linspace(0,2.6,10)
for k = 1:numel(t)
S(k) = fzero(@(S) myfun(S,t(k)),0.03);
end
and you get the result you want.
  댓글 수: 2
RAFFAELE CANTERI
RAFFAELE CANTERI 2020년 10월 12일
thanks!
Star Strider
Star Strider 2020년 10월 13일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by