Solving differential equations involving heaviside function.
10 views (last 30 days)
Show older comments
I have a set of differential equations involving heaviside function. I want to solve it numerically using ode45, however on solving I get all values of y as NaN. But the the derivative functions are not NaN. I think something is going wrong inside ode45. Can anyone guide on how to solve ODEs involving heaviside function using ode45? Please give suitable code snippets if possible.
0 Comments
Answers (1)
Alan Stevens
on 12 Dec 2020
Here's a snippet that works, but it would be better if you uploaded your code, as we stand a better chance of solving your problem that way:
tspan = [0 2];
ic = 1;
[t, y] = ode45(@fn, tspan, ic);
plot(t,y),grid
function dydt = fn(t,y)
u = heaviside(t-1);
dydt = -u*y;
end
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!