# Conversion to logical from sym is not possible.

4 vues (au cours des 30 derniers jours)
Hopejiun Jo le 10 Mar 2021
Commenté : Hopejiun Jo le 11 Mar 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!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### 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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
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)
Hopejiun Jo le 11 Mar 2021
thanks.it can work!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by