Conversion to logical from sym is not possible.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sargondjani
2021-3-10
编辑:Sargondjani
2021-3-10
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 个评论
Walter Roberson
2021-3-11
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!