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

8 ビュー (過去 30 日間)
Benjamin Marrow
Benjamin Marrow 2017 年 8 月 31 日
回答済み: Walter Roberson 2017 年 9 月 1 日
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 Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by