How to use logical operator in syms?

4 ビュー (過去 30 日間)
Yokuna
Yokuna 2022 年 8 月 24 日
回答済み: Walter Roberson 2022 年 8 月 24 日
I want to implement the code having logical operators included in syms, but it gives error. Plese help to use logical operators with syms variable.
clear all
clc
syms x1 x2 x_L x_L1 x_L2 x_r t
L1=(160-x1)*(200-x1)+0.02;
L2=(140-x2)*(200-x2)+0.02;
if (L1<0)
V1=0;
elseif (0<L1<=0.02)
V1=L1^2*0.1/(2*0.02)
else
V1=0.1*(L1^2-0.02/2)
end
Conversion to logical from sym is not possible.
if (L2<0)
V2=0;
elseif (0<L2<=0.02)
V2=L2^2*0.1/(2*0.02)
else
V2=0.1*(L2^2-0.02/2)
end
c1=gama(1)*x1^2+beta(1)*x1+alpha(1)+V1;
c2=gama(2)*x2^2+beta(2)*x2+alpha(2)+V2;

採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 24 日
Use piecewise()

その他の回答 (1 件)

David Hill
David Hill 2022 年 8 月 24 日
if (double(L1)<0)
V1=0;
elseif 0<double(L1)&&double(L1)<=0.02
V1=L1^2*0.1/(2*0.02)
else
V1=0.1*(L1^2-0.02/2)
end

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by