Conversion to logical from sym is not possible.

9 ビュー (過去 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 Center および File ExchangeNumber Theory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by