Conversion to logical from sym is not possible.

3 Ansichten (letzte 30 Tage)
Hopejiun Jo
Hopejiun Jo am 10 Mär. 2021
Kommentiert: Hopejiun Jo am 11 Mär. 2021
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!

Antworten (1)

Sargondjani
Sargondjani am 10 Mär. 2021
Bearbeitet: Sargondjani am 10 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 11 Mär. 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)
Hopejiun Jo
Hopejiun Jo am 11 Mär. 2021
thanks.it can work!

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by