Trouble using ezplot and matlabFunction on a symbolic function defined using symengine "piecewise"

syms x t;
MP_syntax1 = 'piecewise([x <= 10, x/10], [10 < x <= 30, (30 - x)/20])';
MP_syntax2 = 'ilaplace(2/s^3,s,t)';
f(x) = evalin(symengine,MP_syntax1);
g(t) = evalin(symengine,MP_syntax2);
No trouble with g(t) or other MuPad functions:
ezplot(g(t), [-5,5]);
G = matlabFunction(g(t));
Trying the same to the piecewise, f(x) will not work however.
ezplot(f(x),[0,30]);
F = matlabFunction(f(x));
However, this works
xd = 0:0.1:30;
fd = double(f(xd));
plot(xd,fd);
What is wrong with the other calls using ezplot and matlabFunction for f(x) ?

4 件のコメント

Geoff Hayes
Geoff Hayes 2015 年 3 月 29 日
Ronny - what do you mean by f(x) will not work? Are you observing an error or something else?
Sorry for beeing unclear. Calling
"ezplot(f(x),[0,30])" and "matlabFunction(f(x))"
produces errors. However,
"ezplot(g(t),[-5,5])" and "matlabFunction(g(t))"
produces good output.
Errors are:
Error using ezplot (line 162)
piecewise([x <= 10, x/10], [x in Dom::Interval(10, [30]), 3/2 - x/20]) cannot be plotted in the xy-plane.
and
Error using symengine>makeFhandle (line 109)
Error: Unbalanced or unexpected parenthesis or bracket.
Error in symengine (line 60)
Error in sym/matlabFunction (line 125)
g = symengine('makeFhandle',varnames,body);
I am having a similar error. Any solution yet?
Try the new fplot family of functions in R2016a.

サインインしてコメントする。

 採用された回答

Sally Al Khamees
Sally Al Khamees 2016 年 12 月 23 日
編集済み: Sally Al Khamees 2017 年 2 月 21 日
If you have R2016b and the Symbolic Math Toolbox installed, you can just use the piecewise function:
For example:

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by