MATLAB: How to solve coupled non linear ode using ode 45

differential equationsnonlinear odeodeode45

I need to solve the following coupled odes, using ode 45.
  1. dthetadt = -(v/Dc)*log(v*theta/Dc);
2. dvdt = (v/a)*((b*v/Dc)*log(v*theta/Dc));
I wrote the following function. but it is not wotking. if u all have time can u give me some guide about to coding with two coupled equations problem
function [t,theta,v] = call_nonlin_ode()
tspan = [0 365];
theta0 = 10;
[t,theta,v] = ode45(@nonlin_ode,tspan,theta0)
function[dtheta,dvdt]= nonlin_ode(t,theta)
a = 0.01;
b = 0.02;
Dc = 1e-5;
v0 = 1e-2;
dthetadt = -(v/Dc)*log(v*theta/Dc);
dvdt = (v/a)*(b*v/Dc)*log(v*theta/Dc);
end
end

Best Answer

  • When you have a coupled set of ODEs the ode-function has to return a column-vector with the derivatives. So you'll have to modify your function to something like this:
    function[dthetadtdvdt]= nonlin_ode(t,theta_v)
    a = 0.01;
    b = 0.02;
    Dc = 1e-5;
    v0 = 1e-2;
    theta = theta_v(1);
    v = theta_v(2);
    dthetadtdvdt = zeros(2,1);
    dthetadtdvdt(1) = -(v/Dc)*log(v*theta/Dc);
    dthetadtdvdt(2) = (v/a)*(b*v/Dc)*log(v*theta/Dc);
    end
    Then you'll have to modify your call and output-handling correspondingly.
    HTH