Info

此问题已关闭。 请重新打开它进行编辑或回答。

why plots are not matching with ode

1 次查看(过去 30 天)
shiv gaur
shiv gaur 2022-3-12
关闭: Jan 2022-3-12
此 个问题 已被 Jan 标记
% Set parameters
Tstart = 0.0;
Tend = 200.0;
Nt = 200000;
dT = (Tend-Tstart)/Nt;
X0 = 1;
Y0 = 1;
Z0 = 0;
N = 20;
SIGMA = 0.2;
R = 0.2;
B = 5.7;
%
% Initialize coefficient arrays
T = zeros(Nt+1,1);
X = zeros(Nt+1,1);
Y = zeros(Nt+1,1);
Z = zeros(Nt+1,1);
a = zeros(N+1,1);
b = zeros(N+1,1);
c = zeros(N+1,1);
T(1) = 0.0;
X(1) = X0;
Y(1) = Y0;
Z(1) = Z0;
for j = 2:Nt+1
a(1) = X(j-1);
b(1) = Y(j-1);
c(1) = Z(j-1);
for k = 1:N
SB = 0.0;
for i= 0:k-1
SB = SB + a(i+1)*c(k-i);
end
a(k+1) = ((-b(k) - a(k)))/k+1;
b(k+1) = ((a(k) +R*b(k)))/k+1 ;
c(k+1) =( SIGMA-B*c(k) + SB)/k+1 ;
end
x = a(1);
y = b(1);
z = c(1);
for k = 2:N+1
x = x + a(k)*dT^(k-1);
y = y + b(k)*dT^(k-1);
z = z + c(k)*dT^(k-1);
end
T(j) = T(j-1) + dT;
X(j) = x;
Y(j) = y;
Z(j) = z;
end
figure(1)
plot(T,X,'Color','red')
hold on
figure(2)
plot(T,Y,'Color','red')
hold on
figure(3)
plot(T,Z,'Color','red')
hold on
figure(4)
plot3(X,Y,Z,'Color','red')
hold on
%matching with ode
function kk2
close all; clear all;
% accuracy
%options = odeset('RelTol',1e-9,'AbsTol', 1e-16);
a=0.2;
b=0.2;
k=5.7;
[t,y]=ode45(@f,[0 200],[1;1;0.05] );
%plot(t,y(:,2),t,y(:,4),t,y(:,6))
%
plot(t,y(:,1),t,y(:,2),t,y(:,3))
xlabel('t');
ylabel('x,y,z')
%plot3(y(:,1),y(2,:),y(:,3))
function dy=f(t,y)
a=0.2;
b=0.2;
k=5.7;
dy=[(-y(2)-y(3));y(1)+a*y(2);b+y(3)*(y(1)-k)];
end
end
what is the problem above program
  3 个评论
shiv gaur
shiv gaur 2022-3-12
irritating some one who are not able to answer the question he select the choice of closing the question with out giving answer the question this is not simple problem
Jan
Jan 2022-3-12
Your question does not contain enough information to be answered. You state, that the "plots do not match the ODE", but of course the diagrams are the results of the equations. As said already, there is no chance to guess, why you expect different results, because you do not mention any reason.
Re-opening your question without adding any further useful details is a misusage of the forum. Stop this.

回答(0 个)

此问题已关闭。

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by