Piecewise symbolic function with Heaviside and Dirac
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Walter Roberson
2014-4-4
You are attempting to multiply a string by something. As indicated earlier, that cannot work.
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!