Conversion to logical from sym is not possible.
7 views (last 30 days)
Show older comments
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 Comment
KSSV
on 16 Feb 2018
YOu have assigned variable x as symbolic......and you are using x >= 0, without evalating it...how you expect it works?
Accepted Answer
Birdman
on 16 Feb 2018
Edited: Birdman
on 16 Feb 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));
0 Comments
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!