how to combine symbolics and if statement?
Ältere Kommentare anzeigen
Hello, My function is like this
y=x+2 for 0<=x<=10
y = x^2 for 10<x<=500 and x belongs to 0,500.
so I tried like this
syms x
if x>=0 && x<=10
y=x+2
else y=x^2
end
but i am getting an error saying
"Conversion to logical from sym is not possible"
"Operands to the || and && operators must be convertible to logical scalar values".
Please help me how to overcome this.
Akzeptierte Antwort
Weitere Antworten (1)
Karan Gill
am 20 Okt. 2016
Bearbeitet: Karan Gill
am 17 Okt. 2017
In this case:
syms y(x)
y(x) = piecewise(0<=x<=10, x+2, 10<x<=500, x^2);
Now try
y(1)
ans =
3
>> y(12)
ans =
144
1 Kommentar
Walter Roberson
am 20 Okt. 2016
Thanks, Karan, I had missed seeing that.
Kategorien
Mehr zu Assumptions finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!