Conversion to logical from sym is not possible.

조회 수: 13 (최근 30일)
PetronasAMG
PetronasAMG 2018년 2월 16일
편집: Birdman 2018년 2월 16일
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
KSSV 2018년 2월 16일
YOu have assigned variable x as symbolic......and you are using x >= 0, without evalating it...how you expect it works?

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2018년 2월 16일
편집: Birdman 2018년 2월 16일
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개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by