How to use logical operator in syms?

5 visualizzazioni (ultimi 30 giorni)
Yokuna il 24 Ago 2022
Risposto: Walter Roberson il 24 Ago 2022
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;
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Walter Roberson il 24 Ago 2022
Use piecewise()
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Più risposte (1)

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
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

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

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by