# How to numerically solve a differential equation with a dirac delta function ?

27 views (last 30 days)

Show older comments

The differential equation that I want to solve is

Upon using ode45 and the dirac function, the dirac function doesn't seem to have any effect (which makes sense because x never reaches 1 in a numerical solution)

Any ideas on how to solve this numerically?

##### 6 Comments

Alan Stevens
on 1 Jul 2020

### Accepted Answer

Walter Roberson
on 1 Jul 2020

Use ode45 to solve the equation over the start time to time 1 (the place the dirac delta is located.) Do not use the if statements like Alan and Mohit show: just end the integration at the point they would take effect. Using if presents theory problems that you can avoid by just stopping at the place of the event.

Now take the final output of that ode45 and give the appropriate kick to the boundary conditions.

Then restart the ode45 from time 1 to the final desired time, passing in the kicked boundary conditions. Do not use if -- again you avoid the theory problem by not having ode45 cross the interval of discontinuity.

### More Answers (0)

### See Also

### Community Treasure Hunt

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

Start Hunting!