Creating a Piecewise Symbolic function

1 次查看(过去 30 天)
hello!
I need help creating a piecewise function out of 2 symbolic functions. I have:
a = poly2sym(polyfun); %Convert to symbolic
b = poly2sym(polyfun1); %Convert to symbolic
Now I want to create a function f, that is the piecewise composition of a and b. I can use the heavisde function for regular numeric functions like this:
j = '(heaviside(x)-heaviside(x-1))'*x.^2;
But the above is a numeric expression. If I try to make mine numeric by doing:
j = '(heaviside(x)-heaviside(x-1))'*matlabFunction(a)
It returns an error about using "mtimes". A and b are both symbolic, and I need j to be pieciewise and also symbolic. Any ideas?
thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2014-4-2
'(heaviside(x)-heaviside(x-1))'*x.^2 means the string '(heaviside(x)-heaviside(x-1))' matrix-multiplied by the element-wise square of x.
Anything in quotes is a string, not symbolic.
Also, matlabFunction() returns a function handle, not a symbolic function.
syms x
(heaviside(x)-heaviside(x-1)) * a
would be a symbolic expression. You could matlabFunction() the result, I suppose.

更多回答(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