How to write as symbolic piecewise function with conditions on a symbolic vector

조회 수: 1 (최근 30일)
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
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));

채택된 답변

Walter Roberson
Walter Roberson 2023년 2월 24일
n = 4
n = 4
syms Xi [1 n]
condition = fold(@and, abs(Xi)<=1)
condition = 
ff = piecewise(condition, sum(Xi.^2), Inf)
ff = 

추가 답변 (1개)

Torsten
Torsten 2023년 2월 24일
편집: Torsten 2023년 2월 24일
n = 2;
Xi = sym('Xi',[1 n]);
ff = piecewise(max(abs(Xi))<=1,sum(Xi.^2),Inf)
ff = 
fsurf(ff)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by