# Conversion to logical from sym is not possible.

조회 수: 110(최근 30일)
PetronasAMG 16 Feb 2018
편집: Birdman 16 Feb 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

KSSV 16 Feb 2018
YOu have assigned variable x as symbolic......and you are using x >= 0, without evalating it...how you expect it works?

로그인 to comment.

### 채택된 답변

Birdman 16 Feb 2018
편집: Birdman 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));

로그인 to comment.

### 추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.