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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by