Conversion to logical from sym is not possible.
5 views (last 30 days)
Show older comments
my matlab code is the following:
clear
syms rr
g=3
Fr1=(1.8-0.8.*(1+rr)./(1-7.56.*g*rr))
O1=0.01-0.11.*rr+0.06.*exp(23*rr)
eff1=Fr1*rr/O1
x=fminbnd(@(rr)-eff1,-1,1)
after executing this code ,it shows error message:
eff1 = (rr*(((4*rr)/5 + 4/5)/((567*rr)/25 - 1) + 9/5))/((3*exp(23*rr))/50 - (11*rr)/100 + 1/100)
Conversion to logical from sym is not possible.
Error in fminbnd (line 336) if fu <= fx Error in e2 (line 9)
x=fminbnd(@(rr)-eff1,-1,1)
how can i solve this problem?thank a lot!
0 Comments
Answers (1)
Sargondjani
on 10 Mar 2021
Edited: Sargondjani
on 10 Mar 2021
g = 3;
eff1=@(rr)-(1.8-0.8.*(1+rr)./(1-7.56.*g*rr))*rr/(0.01-0.11.*rr+0.06.*exp(23*rr));
x=fminbnd(eff1,-1,1);
You could still define your subfunctions separtately, but this will give you an anwer. You dont need the symbolic stuff.
3 Comments
Walter Roberson
on 11 Mar 2021
Are you asking why your symbolic solution failed? If so then it is because @(rr)-eff1 does not evaluate -eff1 with respect to rr at all, and instead just returns whatever value it had before, namely the symbolic expression; furthermore fminbnd is not designed to work with symbolic outputs.
You would need
x=fminbnd(matlabFuncton(-eff1),-1,1)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!