i am trying to use ode45 in a system of 4 equations

2 ビュー (過去 30 日間)
tasos statiou
tasos statiou 2014 年 10 月 25 日
回答済み: Jan 2014 年 10 月 26 日
the problem is about 2 vortexes Q1(x1,y1),Q2(x2,y2)
the equations are :
dx1/dt=Q2*(y1-y2)/l.^2
dy1/dt=-Q2*(x1-x2)/l.^2
dx2/dt=-Q1*(y2-y1)/l.^2
dy2/dt=Q1*(x1-x2)/l.^2
here is my code :
function[d]=lab2(t,IC)
global Q1 Q2 x1 x2 y1 y2 l
d=zeros(4,1);
d(1)=Q2*(y1-y2)/l.^2;
d(2)=-Q2*(x1-x2)/l.^2;
d(3)=-Q1*(y1-y2)/l.^2;
d(4)=Q1*(x1-x2)/l.^2;
end
i run it on a script :
clear all
close all
clc
Q1=1
Q2=2
x1=1
x2=-1
y1=0
y2=0
l=2
time_interval=linspace(0,10,200);
initial_contitions=[0 1 0 -1];
[T,Sol]=ode45(@lab2,time_interval,initial_contitions);
it says the following when i try to run it:
In an assignment A(I) = B, the number of elements in B
and I must be the same.
Error in lab2 (line 4)
d(1)=Q2*(y1-y2)/l.^2;
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1}
to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...
Error in script (line 13)
[T,Sol]=ode45(@lab2,time_interval,initial_contitions);
i dont know what i m doing wrong...

回答 (1 件)

Jan
Jan 2014 年 10 月 26 日
If I run your code, I do not get an error message. But I've added a defintion of the variables as global in the main program.
But your function to be interagted looks really strange: The derivatrive does neither depend on the time nor on the current values. Then you get an exponential function, which can be solved directly.
Therefore I assume you mean something like this:
function[d]=lab2(t,x)
global Q1 Q2 l
x1 = x(1);
x2 = x(2);
y1 = x(3);
y2 = x(4);
d = zeros(4,1);
d(1) = Q2*(y1-y2)/l.^2;
d(2) = -Q2*(x1-x2)/l.^2;
d(3) = -Q1*(y1-y2)/l.^2;
d(4) = Q1*(x1-x2)/l.^2;
end

カテゴリ

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