How to use logical operator in syms?

3 views (last 30 days)
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;

Accepted Answer

Walter Roberson
Walter Roberson on 24 Aug 2022
Use piecewise()

More Answers (1)

David Hill
David Hill on 24 Aug 2022
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

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!