Conversion to logical from sym is not possible.

7 vues (au cours des 30 derniers jours)
PetronasAMG
PetronasAMG le 16 Fév 2018
Modifié(e) : Birdman le 16 Fév 2018
This is what I have
syms x;
c = 12;
xmax = 5
if x >= 0 && x < xmax
y1 = symfun(c*((-((4)/(2.^2))*(x/c).^2)) + (4)/5*2)*(x/c)));
end
if x >= xmax && x < c
y2 = symfun((((c*2))/(100-(20*3)+3^2)))*((-(x/c).^2+ (3/5)*(x/c))+ (1-2/5)))));
end
plot(x,yc1);
hold on
plot(x,yc2);
grid on;
I get an error that says Conversion to logical from sym is not possible before it even calculates y1. I am new to this function. Any suggestions? also is there a better way to combine these two graphs? thank you!
  1 commentaire
KSSV
KSSV le 16 Fév 2018
YOu have assigned variable x as symbolic......and you are using x >= 0, without evalating it...how you expect it works?

Connectez-vous pour commenter.

Réponse acceptée

Birdman
Birdman le 16 Fév 2018
Modifié(e) : Birdman le 16 Fév 2018
What you need here is piecewise function:
syms x;
c = 12;
xmax = 5;
y1=c*((-((4)/(2.^2))*(x/c).^2)) + (4)/5*2*(x/c);
y2=(((c*2))/(100-(20*3)+3^2))*((-(x/c).^2+ (3/5)*(x/c))+ (1-2/5));
y(x)=piecewise(0<=x<xmax,y1,xmax<=x<c,y2);
x=0:0.01:10;%random data for x
plot(x,y(x));

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by