Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to solve simultaneous ODE equations in matlab with if/else if?

조회 수: 1 (최근 30일)
MINA
MINA 2014년 7월 28일
마감: MINA 2014년 7월 30일
Hello, I have a set of ODE and I am writing the matlab code to solve it but unfortunately I don't get the right result, i.e., it becomes very slow. Could you please tell me where I am making mistake? I even used ode23s, but still the problem exists.
Here is the ODE:
surface.
And here is my matlab code:
function [ x,y,z ] = lorenz_like( alpha, beta, gamma,theta,const, initV, T, eps )
%This function generates data from Lorenz-like system
if nargin<5
error('MATLAB:lorenz:NotEnoughInputs','Not enough input arguments.');
end
if nargin<6
eps = 0.000001;
delta_t=0.01;
T =0:delta_t:100;
initV = [40 40 0];
end
options = odeset('RelTol',eps,'AbsTol',[eps eps eps/10]);
[T,X] = ode45(@(T,X) F(T, X, alpha, beta, gamma,theta,const), T, initV, options);
x = X(:,1);
y = X(:,2);
z = X(:,3);
return
end
function dx = F(T, X, alpha, beta, gamma,theta,const)
dx = zeros(3,1);
x_1p=-14;
x_2p=-12;
x_3p=0;
x_1o=0;
x_2o=0;
x_3o=5;
x_1n=14;
x_2n=12;
x_3n=0;
A=[-alpha alpha 0;
beta-x_3p -1 -x_1p;
x_2p x_1p -gamma];
A_x=[X(1)-x_1p;
X(2)-x_2p
X(3)-x_3p];
B=[-alpha alpha 0;
beta-x_3o -1 -x_1o;
x_2o x_1o -gamma ];
B_x=[X(1)-x_1o;
X(2)-x_2o
X(3)-x_3o];
C=[-alpha alpha 0;
beta-x_3n -1 -x_1n;
x_2n x_1n -gamma];
C_x=[X(1)-x_1n;
X(2)-x_2n
X(3)-x_3n];
condition= X(1)*tan(theta)+X(2);
if condition>const
dx=A*A_x;
elseif -const<=condition && condition<=const
dx=B*B_x;
else
dx=C*C_x;
end
return
end
  댓글 수: 3
MINA
MINA 2014년 7월 29일
For the input data you would just need to call:
[ x,y,z ] = lorenz_like( 10, 9, 4,pi/2,4 );
And then if you plot x for example you need to get this figure(a) and if you plot(x,y) you need to get figure(b)
MINA
MINA 2014년 7월 29일
It is solved now. The code is right. The number that was given in paper was not correct. I changed the number and I got the same result. Thanks

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by