Dirac function and matlabFunction

조회 수: 4 (최근 30일)
jim
jim 2014년 4월 3일
답변: Walter Roberson 2014년 4월 4일
hello!
I'm having problems evaluating a matlab function that has dirac within. I have the following symbolic function: mf = v^2*dirac(x + 0.5) + 3*v^2*dirac(x + 0.5, 1)
I then created a matlab function by doing this: ht = matlabFunction(mf)
ht = @(v,x)(v.^2.*dirac(x + 0.5) + 3.*.v.^2.*dirac(x + 0.5, 1))
Everything works well. But when I then try to evaluate the function by doing this:
ht(2, 7)
I get an error. It says "Error using dirac. Too many input arguments." How do I evaluate that function correctly?
thanks in advance!

답변 (4개)

Carlos
Carlos 2014년 4월 3일
편집: Carlos 2014년 4월 3일
The problem is this line of the code dirac(x + 0.5, 1), dirac only allows one argument. Why do you include the second parameter 1? What do you want to represent? Just a dirac function centered in -0.5? then just write dirac(x + 0.5) as in the previous command

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 3일
In your expression what is dirac(x+0.5,1)? it should be dirac(x+0.5)
ht = @(v,x)(v.^2.*dirac(x + 0.5) + 3*v.^2.*dirac(x + 0.5))
ht(2,7)

jim
jim 2014년 4월 3일
Well, I am using the heaviside function in an earlier expression called 'z'. When I took it's derivative by doing this:
mf = diff(z)
I got this:
mf = v^2*dirac(x + 0.5) + 3*v^2*dirac(x + 0.5, 1)
So that's where that came from.
After that I created a matlab function by doing this:
ht = matlabFunction(mf)
which gives
ht = @(v,x)(v.^2.*dirac(x + 0.5) + 3.*.v.^2.*dirac(x + 0.5, 1))
Again, everything works well. I just can't evaluate it. It gives me an error when I do h(2,7).
  댓글 수: 1
Carlos
Carlos 2014년 4월 3일
Try with
mf = v^2*dirac(x + 0.5) + 3*v^2*dirac(x + 0.5)

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


Walter Roberson
Walter Roberson 2014년 4월 4일
Please show the z formula for which mf is the derivative.
It appears to me that your z most likely contains dirac and not heaviside and that dirac(x + 0.5,1) is an attempt to represent the first derivative of the dirac function.
Which MATLAB version are you using? Are you possibly using Maple as your symbolic engine instead of MuPAD ?

Community Treasure Hunt

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

Start Hunting!

Translated by