Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
MINA
MINA am 28 Jul. 2014
Geschlossen: MINA am 30 Jul. 2014
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 Kommentare
MINA
MINA am 29 Jul. 2014
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 am 29 Jul. 2014
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

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by