Autonomous linear differential equation with varying coefficients
Show older comments
Hi everybody, I need your kind suggestion about the following issue. I'm concerned in solving a differential equation in the function y(t). With y' and y'' I refer to the first and second time-derivative respectively. The equation is: y'' + a(y)y' + b(y)y = 0 y(0) = 2.1; y'(0) = 0; a, b are known per each value of the vector ips = [1.5,2], i.e. the configuration space which y belongs to. I tried the following strategy: I defined the vector tspan and called the ode45 solver;
tspan = 0:0.001:5;
ic = [2.1000 0];
opt=odeset('MaxStep',0.001);
[t,x] = ode45(@(t,x) myfun(t,x,ips,a,b), tspan, ic, opt);
the function myfun is:
function dxdt = myfun(t,x,ips,a,b)
dxdt = zeros(2,1) ;
a = interp1( ips, a, x(1),'linear' );
b = interp1( ips, b, x(1),'linear' );
dxdt(1,1) = x(2);
dxdt(2,1) = - b.*x(1) - a.*x(2) ;
This scheme does not work, since from some t on, solution is NaN.
Can anybody help me?
Thanks in advance
Answers (0)
Categories
Find more on Get Started with Curve Fitting 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!