Conversion to logical from sym is not possible.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Sargondjani
le 10 Mar 2021
Modifié(e) : Sargondjani
le 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 commentaires
Walter Roberson
le 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)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!