Basic ODE question

8 ビュー (過去 30 日間)
Seth
Seth 2011 年 3 月 4 日
回答済み: jagathi medempudi 2020 年 8 月 27 日
So...it's been quite a while since I solved any systems of ODEs and I am admittedly very rusty. I am hoping there is a simple answer to this question:
I have a coupled system of ODEs:
dA/dc=-0.5*(2-v)*(1-v^2)/(1-v)
and
dv/dc=-1.5*(5-v)*(1-v^2)/(3-v)
Solve from c=[0 1]
Initial conditions: Ao=100, vo=0.5
How can I set this up in a Matlab function? Thanks for any advice!

採用された回答

Matt Tearle
Matt Tearle 2011 年 3 月 5 日
  1. Write a function that defines the rate equations. The system should now look like z' = f(c,z), where z = [A;v]. Write your function file so that it takes c and a vector z as inputs, and returns a vector dz that represents the derivatives ([A';v'])
  2. Use ode45 to solve the system, giving a function handle to you function from step 2 as input, as well as the vector of start and end values for c and the initial conditions z0 = [A0;v0].
  3. Extract the components of the solution returned by ode45 to plot as a function of c (also returned by ode45). (If A and v are on the same scale, you could just do plot(c,z))
Your question is mainly about step 1. So write a function file
function dz = functionname(c,z)
dz = zeros(size(z));
% extract components of z (ie A & c)
% define dz(1) according to the equation for dA/dc
% define dz(2) according to the equation for dv/dc

その他の回答 (3 件)

Seth
Seth 2011 年 3 月 7 日
Solved the problem by simply decoupling and doing two independent ODE45 solves instead of treating as a system of equations. I understand this is not the best way - but worked fine for my problem.
Thanks Matt for the help.

SHOBHIT KUMAR
SHOBHIT KUMAR 2019 年 6 月 9 日
can we not just do this and find the solution from gtaph and get the answer?
sol=dsolve('Da=-0.5*(2-v)*(1-v^2)/(1-v)','a(0)=100','c');
ezplot(sol,[-2 2])
hold on;
s=dsolve('Dv=-1.5*(5-v)*(1-v^2)/(3-v)','v(0)=0.5','c');
ezplot(s,[-2 2])
Please answer

jagathi medempudi
jagathi medempudi 2020 年 8 月 27 日
What is the mat lab command for solving differential equation
Select one:
a. differentiation
b. dsolve
c. int
d. diff

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by