How do I plot a particular solution (with given initial conditions) of 3 differential equations with 3 variables?

The equations are the Lorentz equations:
x(dot) = sigma(y-x)
y(dot) = rx - y - xz
z(dot) = xy - bz
where sigma, r and b are fixed. I need to simulate them for various initial conditions. First off, I'm kind of sketchy on what simulate even means. I've asked around elsewhere and gotten as far as I need to use one of the built in ode solvers? like ode45 or ode1 or something. I'm just not sure how to define all 3 functions at once, or whether I even need to do that? Someone said that it wasn't necessary but I didn't understand why.
How do I tell matlab to solve all of these equations at once and give me an x-y-z plot of the trajectory obtained from a given initial (x,y,z)?

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 5 月 18 日
編集済み: Mischa Kim 2014 年 5 月 18 日
Andrew, use ode45 and something like
function Lorentz()
sigma = 1;
r = 1;
b = 1;
[~,S] = ode45(@EOM,[0 50],[1 2 3],[],sigma,r,b);
x = S(:,1);
y = S(:,2);
z = S(:,3)
plot3(x,y,z)
box
end
function dS = EOM(t,s,sigma,r,b)
x = s(1);
y = s(2);
z = s(3);
dS = [sigma*(y - x);...
r*x - y - x*z;...
x*y - b*z];
end
Note, the three equations are coupled, therefore they need to be solved simultaneously.

5 件のコメント

Andrew Davies
Andrew Davies 2014 年 5 月 18 日
編集済み: Andrew Davies 2014 年 5 月 18 日
First of all, thanks for helping out. I'm quite a novice with Matlab so forgive me if some of these questions are silly.
What does EOM mean? and the @ symbol, i'm confused about the function of the @ smybol.
Also, [~,S]? And it says Error: Function definitions are not permitted at the prompt or in scripts.
Sorry if I sound like a retard, and thanks again.
Mischa Kim
Mischa Kim 2014 年 5 月 18 日
EOM is simply the name of the function that defines the differential equations. The ode45 command returns time as the first argument (in addition to state vector). The ~ is typically used to point out that a variable - in this case time - is not further used in the simulation.
What about the first line, function Lorentz (), what is that for?
Mischa Kim
Mischa Kim 2014 年 5 月 18 日
That's called a function. Simply copy-paste the entire code into one file, save it as Lorentz.m and run it from the command window.
Actually, that line defines the file as a function rather than as a main script file. A function file has special properties.

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 5 月 18 日

コメント済み:

2014 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by