Dirac function and matlabFunction

7 views (last 30 days)
jim
jim on 3 Apr 2014
Answered: Walter Roberson on 4 Apr 2014
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!

Answers (4)

Carlos
Carlos on 3 Apr 2014
Edited: Carlos on 3 Apr 2014
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 on 3 Apr 2014
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 on 3 Apr 2014
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).

Walter Roberson
Walter Roberson on 4 Apr 2014
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!