How to solve coupled non linear ode using ode 45

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

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 5월 10일

0 개 추천

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

댓글 수: 3

thank you so much Bjorn Gustavsson. can you please help me with how to call the ode45 solution if i to derive theta and v. Will it work?
[t, theta] = ode45(dthetadtdvdt(1),tSpan,theta0);
[t, v] = ode45(dthetadtdvdt(2),tSpan,v0);
Please read the documentation:
Example
[t,y]=ode45(@vdp1,[0 20],[2 0]);
plot(t,y(:,1));
solves the system y' = vdp1(t,y), using the default relative error
tolerance 1e-3 and the default absolute tolerance of 1e-6 for each
component, and plots the first component of the solution.
There you see that the variable y will have some number of of components, and the first is ploted, you also see that the tSpan used there is from 0 to 20 and that the initial condition has two components - that is an initial conditoin for the first and the second component of y. For your problem where you have 2 coupled equations you will also have 2 initial conditions, one for theta and one for v, and your solution should have 2 columns (the first for theta and the second for v). Your call sould be something like this:
[t, theta_v] = ode45(@(t,th_v) nonlin_ode(t,th_v),tSpan,[theta0, v0]);
which should give you both theta and v as the first and second column of theta_v.
HTH
Thank you so much SIr.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by