- dirac(n,x) represents the n-th derivative of the Dirac delta function at x.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to plot dirac n-th derivation ?
3 views (last 30 days)
Show older comments
I dont know how to plot this function which contains first and second derivation of dirac.
This is how i tried to solve it
Y= 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(t,1) + 159*dirac(t,2) + 124126*(t^3);
ezplot(Y ,[0 1])
But Matlab send me:
Error using sym/dirac
Too many input arguments
Can someone please help. Thanks
Accepted Answer
Star Strider
on 31 Aug 2015
You have the arguments to dirac reversed.
From the documentation:
36 Comments
Star Strider
on 31 Aug 2015
This works for me:
syms t
Y= 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(1,t) + 159*dirac(2,t) + 124126*(t^3);
figure(1)
ezplot(Y ,[0 1])
I suggest you send the code that created your original ‘Y’ to MathWorks as a bug report. The Symbolic Math Toolbox should be producing consistent code. It is quite possible that you’re the first to discover this problem. Also, include the URL of this post, http://www.mathworks.com/matlabcentral/answers/238437-how-to-plot-dirac-n-th-derivation, to give it a context.
Walter Roberson
on 31 Aug 2015
joejonson, which MATLAB version are you using?
Walter Roberson
on 31 Aug 2015
The MuPAD version of dirac() has the derivative number after the expression but the interface that the Symbolic Toolkit provides from MATLAB to call MuPAD has the derivative number before the expression. If you attempted to use MuPAD code directly in MATLAB then the arguments would be in the wrong order.
The present order has been used at the MATLAB level since R2007b when MuPAD replaced Maple as the symbolic engine.
Could you check which version of dirac you are invoking?
which -all dirac
Walter Roberson
on 31 Aug 2015
That does look appropriate.
If you use Star Strider's code,
syms t
Y = 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(1,t) + 159*dirac(2,t) + 124126*(t^3);
then do you get the error at that point, or do you get the error when ezplot is processing it? If you use
subs(Y, t, 5.4321)
does that trigger the error? If not then does double() of the result trigger the error ?
Walter Roberson
on 31 Aug 2015
As an experiment, try
syms t
Y = 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*diff(dirac(t,t) + 159*diff(dirac(t),t,t) + 124126*(t^3)
what does it return?
Walter Roberson
on 31 Aug 2015
Correction,
syms t
Y = 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*diff(dirac(t),t) + 159*diff(dirac(t),t,t) + 124126*(t^3)
Walter Roberson
on 31 Aug 2015
I do not know why I didn't find it before, but according to the release notes, the two-input form of dirac is new as of R2014b.
Are you able to ezplot() the version that uses dirac(t,1) ?
It appears that it is treating dirac(t,2) as being equal to dirac(t,1) which does not appear to be correct.
I would be interested to see the result of
evalin(symengine, '80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*diff(dirac(t),t) + 159*diff(dirac(t),t,t) + 124126*(t^3)')
and
evalin(symengine, '80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(t,1) + 159*dirac(t,2) + 124126*(t^3)')
Walter Roberson
on 31 Aug 2015
Okay, so the workaround is this:
dirac = @(varargin) feval(symengine, 'dirac', varargin{:})
However, I have a suspicion you might be encountering https://www.mathworks.com/support/bugreports/details/571941 or https://www.mathworks.com/support/bugreports/details/578535, both of which are marked as fixed as of R2010b. Both of them are about problems with simplifying expressions that contain derivatives of dirac. Perhaps the fix did not really "take". Try simplify() the output of one of the evalin() and see if the expression changes.
Star Strider
on 1 Sep 2015
Walter, Joe — I apologise for appearing to abandon this. I didn’t intentionally. Had to take a comatose laptop for repairs, an 85 km round-trip.
Star Strider
on 1 Sep 2015
I thought I did the plot. I don’t have access to R2012b. (This machine has Win 10 so I can’t install anything earlier that R2015a on it; the comatose computer has R2013a.)
With this code:
syms t
Y= 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(1,t) + 159*dirac(2,t) + 124126*(t^3);
figure(1)
ezplot(Y ,[0 1])
This is the plot I get:

Star Strider
on 1 Sep 2015
I don’t see any transients:

Star Strider
on 1 Sep 2015
My pleasure.
No real changes in the shape of the curve, and no transients. I also looked at ranges from 1E-3 to 1E+7.
Star Strider
on 1 Sep 2015
My (our) pleasure. Walter — thanks for picking this up and exploring it while I was out running errands. (Life intrudes.)
No bother, but if you want us to see what you did with your dynamical system to get the result you did, describe it and post your code. No promises, but we might be able to help with it. If you expect transients, something went wrong somewhere. (If I remember correctly, the delta function should integrate to a constant.)
joejonson
on 1 Sep 2015
Edited: joejonson
on 1 Sep 2015
This is how my code looks like:
syms s t;
Rb=0.043;
Ra=1.071;
La=6.824;
Lb=0.272;
M=1.36;
C=0.000398;
i1=(200*((Rb + s*Lb + 1/(C*s))/((s^3)*(La*Lb*M - M^2)) + (s^2)*(Ra*Lb*M + La*Rb*M) + s*(M*Ra*Rb + La*M/C) + M*Ra/C));
F=ilaplace(i1);
pretty (F)
ezplot(F ,[0 1])
ylabel('I [A]')
xlabel('t [s]')
Star Strider
on 1 Sep 2015
How did you get i1?
Is it a circuit analysis problem? If so, what does the circuit look like?
joejonson
on 1 Sep 2015
It is circuit analysis.This is how it looks like:

There is no much parameters,just transformers primary and secundary resistance (Ra,Rb) and inductance(La,Lb) ,mutual inductance (M) and capacity (C).DC voltage is 200 V (step function).
I get i1 analizing this circuit in Laplace domain (two equations with two unknowns)
joejonson
on 1 Sep 2015
Edited: joejonson
on 1 Sep 2015
I wrote the code in a simpler format and now everything is OK. I now got this :

This is something that I was expecting, beacuse at previuos pictures current goes to infinetly, so i was thinking that it will on some point start decreasing to zero,but that does not happend. The problem was created when i want to make final equation simpler, but actually I made it much complicated, and somewhere probably made mistake on multiplying.
Star Strider
on 1 Sep 2015
I’m getting similar results (no transients) with my independent analysis. I can’t find the error. It most likely has to do with my not having done anything with transformers in a very long time.
The Laplace transform of the delta function is 1, and the step is 1/s, and since these are mutliplied by the transfer function, they shouldn’t show up as separate entities in the result.
joejonson
on 1 Sep 2015
I think it is OK now. I was expecting some transient only beacuse current was raising to infinitely. That was strange to me, so I was thinking it will maybe at some point stop raising,and start decreasing to zero. These new results are looking much better.
Star Strider
on 1 Sep 2015
What you’re getting now is what I would expect. The capacitor charges and the current eventually goes to zero in the secondary circuit. I got similar results.
Star Strider
on 1 Sep 2015
My (our) pleasure!
More Answers (0)
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
