필터 지우기
필터 지우기

This is the 4d Lorenz equation. how to solve it on Matlab?

조회 수: 3 (최근 30일)
Nix Jr
Nix Jr 2021년 7월 25일
편집: Yongzhen Mi 2021년 7월 26일
dx/dt=y+y^2-a*y*z;
dy/dt=-z^2+b*y*z-u;
dz/dt=x*y;
du/dt=-c*x;
  댓글 수: 2
John D'Errico
John D'Errico 2021년 7월 25일
Hint: Read the help for ODE45.
Nix Jr
Nix Jr 2021년 7월 25일
Here has the function with code. But I didn't understand what's the problem. If you don't mind, would you please help me to fix the problem?
...............................................................function..........................................
function df = test(~, x)
% HELP: Lorenz Functions
%dx/dt=y+y^2-a*y*z;
%dy/dt=-z^2+b*y*z-u;
%dz/dt=x*y;
%du/dt=-c*x;
u=10; a=8/3; b=7; c=.5;
% ICs: x(0)=5; y(0)=5; z(0)=5; % Your ICs
df=[x(2)+([x(2)]^2)-a*x(2).*x(3); ...
-([x(3)]^2)+b*x(2).*x(3)-x(4);...
x(1).*x(2)...
-c*x(1)];
end
...................................................................................main code...........................
ICs=[5, 5, 5]; % Your data
t=[0, 20]; % Your simulation space
OPTs = odeset('reltol', 1e-6, 'abstol', 1e-8); % Optional ODE options set up
[time, fOUT]=ode45(@test, t, ICs, OPTs);
close all
figure
plot3(fOUT(:,1), fOUT(:,2), fOUT(:,3), grid
xlabel('x(t)'), ylabel('y(t)'), zlabel('z(t)')
title('LORENZ functions x(t) vs. y(t) vs. z(t)')
axis tight
figure plot3(fOUT(:,1), fOUT(:,2), fOUT(:,3),
figure
subplot(311)
plot(time, fOUT(:,1), 'b','linewidth', 3), grid minor
title 'LORENZ functions x(t), y(t), z(t)', xlabel 'time', ylabel 'x(t)'
subplot(312)
plot( time', fOUT(:,2), 'r', 'linewidth', 2 ), grid minor
xlabel 'time', ylabel 'y(t)'
subplot(313)
plot(time, fOUT(:,3),'k', 'linewidth', 2), grid minor, xlabel 'time', ylabel 'z(t)'
figure
plot(fOUT(:,1), fOUT(:,2), 'b', 'linewidth', 1.5)
grid minor, title('LORENZ functions'), xlabel('x(t)'), ylabel 'y(t)'
axis square
figure
plot(fOUT(:,1), fOUT(:,3), 'k', 'linewidth', 1.5)
grid minor, title('LORENZ functions'), xlabel('x(t)'), ylabel 'z(t)'
axis square
figure
plot(fOUT(:,2), fOUT(:,3), 'm', 'linewidth', 1.5)
grid minor, title('LORENZ functions'), xlabel('y(t)'), ylabel 'z(t)'
axis square

댓글을 달려면 로그인하십시오.

답변 (1개)

Yongzhen Mi
Yongzhen Mi 2021년 7월 26일
Hi, Nix Jr. I think the error is that you defined four variables in your differential equations, but you provided only three initial values to the ode45 function. Therefore, ICs should be something like this [5, 5, 5, 5]' (column vector better).
In addition, you can transfer parameters into the target function by using [time, fOUT]=ode45(@(x)test(~,x,a,b,c), t, ICs, OPTs);. In this way, the parameters a, b, and c can be claimed in the main function once, instead of being defined again and again when the target function is called.
  댓글 수: 2
Nix Jr
Nix Jr 2021년 7월 26일
Thanks for you suggestion but this process doesn't work. or might be I didn't get your process.
Yongzhen Mi
Yongzhen Mi 2021년 7월 26일
편집: Yongzhen Mi 2021년 7월 26일
Take this as an example:
a = 5;
b = 20;
c = 1;
d = 0.1;
k = 0.1;
e = 20.6;
h = 1;
F = @(t,Y) [a*(Y(2)-Y(1))-e*Y(4);Y(1)*Y(3)-h*Y(2);b-Y(1)*Y(2)-c*Y(3);k*Y(2)-d*Y(4)];
CI = [3.2 8.5 3.5 2.0]';
T = linspace(0,100,3000);
[t,Y]=ode45(F,T,CI);
plot3(Y(:,1),Y(:,2),Y(:,3))
I drew some pictures and the attractors could be observed. Please try again and hopefully this will work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by