How to write as symbolic piecewise function with conditions on a symbolic vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
David Gillcrist
am 24 Feb. 2023
Bearbeitet: Torsten
am 24 Feb. 2023
I have a symbolic vector, and I want to define a function that is an
parabola if the vector is inside a hyper cube of length 2 centered at the origin, and otherwise it's infinity. This is what I've written
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305980/image.png)
syms Xi [1 n]
ff = piecewise(all(abs(Xi)<=1),sum(Xi.^2),Inf);
This function however produces the error
Error using symengine
Unable to prove 'abs(Xi1) <= 1' literally. Use 'isAlways' to test the statement mathematically.
Error in sym>logicalNaNIsTrue (line 2054)
X = mupadmex('symobj::logicalNaNIsTrue',A.s,9);
Error in sym/all (line 623)
X = all(logicalNaNIsTrue(A));
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 24 Feb. 2023
n = 4
syms Xi [1 n]
condition = fold(@and, abs(Xi)<=1)
ff = piecewise(condition, sum(Xi.^2), Inf)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!