Solve a system of ODEs with a piecewise forcing function
Show older comments
I'm trying to solve a system of two ODEs with a piecewise forcing function. There are two cases, the first being instantaneous changes of the constant function. The second involves a linear decrease and increase. I haven't been able to make this work with the first case, and I'm hoping the solution works for the second as well. My code looks something like this:
funlev = [funlev1 0.5*funlev1 funlev1 0];
funp = mkpp([-12 0 48 72 180],funlev);
fun = ppval(funp,t);
fun2 = @(t,y) [A*fun-B*y(1);
B*y(1)+C-D*y(2)-E*fun*y(2)];
[t1,y1] = ode45(fun2,[-12 180],y0);
I'm thinking the issue is with the piecewise function, but I'm not positive. Am I missing something? If I'm not handling the piecewise function correctly, how would I do so?
Answers (0)
Categories
Find more on Ordinary Differential Equations 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!