Piecewise symbolic function with Heaviside and Dirac
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Walter Roberson
on 4 Apr 2014
You are attempting to multiply a string by something. As indicated earlier, that cannot work.
1 Comment
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!