필터 지우기
필터 지우기

Creating a Piecewise Symbolic function

조회 수: 1 (최근 30일)
jim
jim 2014년 4월 2일
답변: Walter Roberson 2014년 4월 2일
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