필터 지우기
필터 지우기

Piecewise symbolic function with Heaviside and Dirac

조회 수: 3 (최근 30일)
jim
jim 2014년 4월 4일
댓글: Walter Roberson 2014년 4월 4일
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

답변 (2개)

Walter Roberson
Walter Roberson 2014년 4월 4일
You are attempting to multiply a string by something. As indicated earlier, that cannot work.
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 4월 4일
f = feval(symengine, 'piecewise', [x >= 1, a], [sym('Otherwise'), b])

댓글을 달려면 로그인하십시오.


jim
jim 2014년 4월 4일
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.

카테고리

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