Creating a Piecewise Symbolic function
3 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Walter Roberson
on 2 Apr 2014
'(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 Comments
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!