How do I extract the function from a piecewise defined function in Matlab?

조회 수: 8 (최근 30일)
I'm using the new Matlab piecewise function https://www.mathworks.com/help/symbolic/piecewise.html introduced in the Symbolic Math Toolbox R2016b to define a function, and I'm trying to extract the function expression part from the whole piecewise variable. Specifically my code looks something like:
syms x;
y = piecewise(x>1,3*x^2,0);
I'd like to be able to extract just the
3*x^2
from y without the condition.
Any idea how to do that?
  댓글 수: 1
Nicolas Schmit
Nicolas Schmit 2017년 9월 1일
Hello. Assume x>1 then simplify the expression.
syms x
y = piecewise(x>1,3*x^2,0);
assume (x>1);
simplify(y)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 1일
You can use children() to extract the subexpressions of a symbolic expression.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by