Clear Filters
Clear Filters

Piecewise symbolic function with Heaviside and Dirac

3 views (last 30 days)
hello!
I need help creating a piecewise function from 2 symbolic functions. Everything works well, I can form the piecewise function, and take its second derivative. But when I try to evaluate the second derivative, it gives me an error with Dirac. Here are my 2 functions:
syms x
a = x^6 + x^5;
b = x^6 + x;
f = '(heaviside(x)-heaviside(x-1))'*a + '(heaviside(x-1))'*b; %0<x<1 use function a, and x>=1 use function b
f_double_prime = diff(diff(f)); % take the second derivative of the piecewise function f
ht = matlabFunction(f_double_prime); %create a matlab function
ht(2); %evaluate the function at x = 2
The last line gives me the error: " Error using dirac. Too many input arguments. " I believe it's because the matlab function 'ht' contains terms like this '(dirac(x - 1, 1)' which gives matlab problems.
How do I correctly evaluate the function? Clearly ht(2) does not work. What is the correct syntax? Is their a better way to form a piecewise function from 2 symbolic functions?
*Please note*** I cannot first take the second derivative of each separate function first...AND THEN form the piecewise function. This is because the existing code would not work, so I have to follow their system.
thanks in advance

Answers (2)

Walter Roberson
Walter Roberson on 4 Apr 2014
You are attempting to multiply a string by something. As indicated earlier, that cannot work.

jim
jim on 4 Apr 2014
No, it does work. You can try it yourself. It gives the correct answer. However, when I try to evaluate it, it cannot substitute terms for the dirac(x-1, 1) term. There must be a way to evaluate my final matlab function.
Again, everything works well. I'm able to construct the piecewise symbolic function, take its second derivative, and form a matlab function from it. But I just can't seem to be able to evaluate the matlab function.

Community Treasure Hunt

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

Start Hunting!