Effacer les filtres
Effacer les filtres

How to use logical operator in syms?

3 vues (au cours des 30 derniers jours)
Yokuna
Yokuna le 24 Août 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;

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Août 2022
Use piecewise()

Plus de réponses (1)

David Hill
David Hill le 24 Août 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

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by