How to use logical operator in syms?

4 visualizzazioni (ultimi 30 giorni)
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;

Risposta accettata

Walter Roberson
Walter Roberson il 24 Ago 2022
Use piecewise()

Più risposte (1)

David Hill
David Hill il 24 Ago 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

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by