my program is not working properly

function kk2
close all; clear all;
% accuracy
%options = odeset('RelTol',1e-9,'AbsTol', 1e-16);
[t,y]=ode45(@f,[0 100],[0.1;0.1;0.1+1;0.1;0.1;0.1] );
plot(t,y(:,2),t,y(:,4),t,y(:,6))
function dy=f(t,y)
%x=y(1);y=y(3);z=y(5)
r=28;
b=8/3;
k=10;
dy=zeros(6,1)
dy= [y(2);k^2*y(1)-k^2*y(3)-k*y(1)*y(5)+k*r*y(5)-k*y(3);y(4);b*y(1)*y(5)-y(1)^2*y(3)-k*y(1)*y(3)+k*y(3)*y(5)-r*k*y(1)+k*r*y(3)+y(1)*y(5)-r*y(1)+y(3);y(6);-y(1)^2*y(5)+r*y(1)^2-y(1)*y(3)-k*y(1)*y(3)+k*y(3)^2-b*y(1)*y(3)+b^2*y(5)]
end
end
so sir we want to plot between t,x,t,y
and we want to plot t vs second element of dy t,fourth element t,vs sixth element

1 件のコメント

Jan
Jan 2022 年 3 月 12 日
編集済み: Jan 2022 年 3 月 12 日
@shiv gaur: You have been asked repeatedly to use a proper code formatting. Please read and consider this: https://www.mathworks.com/matlabcentral/answers/help/rtc#rtc_summary . Thanks.

サインインしてコメントする。

回答 (1 件)

Sam Chak
Sam Chak 2022 年 3 月 11 日
編集済み: Sam Chak 2022 年 3 月 11 日

1 投票

It appears that the system is highly unstable and all states blow up at around 0.35 sec except for . Please check the state equations again. Sometimes, the plus/minus signs can make a huge difference.
Edit: It has some similarities like the Lorenz system, because I recognized the magic values: 10, 8/3, 28.
clear all; clc
r = 28;
b = 8/3;
k = 10;
tspan = linspace(0, 0.3, 10001)';
fun = @(t, y) [y(2); ...
k^2*y(1) - k^2*y(3) - k*y(1)*y(5) + k*r*y(5) - k*y(3); ...
y(4); ...
b*y(1)*y(5) - y(1)^2*y(3) - k*y(1)*y(3) + k*y(3)*y(5) - r*k*y(1) + k*r*y(3) + y(1)*y(5) - r*y(1) + y(3); ...
y(6); ...
- y(1)^2*y(5) + r*y(1)^2 - y(1)*y(3) - k*y(1)*y(3) + k*y(3)^2 - b*y(1)*y(3) + b^2*y(5)];
[t, y] = ode45(fun, tspan, [0.1, 0.1, 1.1, 0.1, 0.1, 0.1]);
plot(t, y)
Once you have fixed the model, please ensure that all states can propagate at least until your desired final time, sec, and then you can choose what you want to plot.

6 件のコメント

shiv gaur
shiv gaur 2022 年 3 月 11 日
how we plot t,second element t vs fourth element t vs six element in equation
Sam Chak
Sam Chak 2022 年 3 月 11 日
Try this:
plot(t, y(:, 2), t, y(:, 4), t, y(:, 6))
shiv gaur
shiv gaur 2022 年 3 月 11 日
Warning: Failure at t=3.541457e-01. Unable to meet integration tolerances without reducing the step size below the
smallest value allowed (8.881784e-16) at time t.
this is the error
Sam Chak
Sam Chak 2022 年 3 月 11 日
編集済み: Sam Chak 2022 年 3 月 11 日
Thought I have put my explanations above. The nature of your state equations is highly unstable. It cannot integrate the system pass 0.3541457 sec. That's why I simulated until 0.3 sec to show you the divergence of the states.
If you are very sure that your system is stable, please double check all 6 state equations, especially on the plus/minus signs. Both human error or publishing error (on the reference) can happen.
It's a very common error. So, no worries. You will find it if you look harder.
Would you tell what the system is? Is it a kind of attractor?
Sam Chak
Sam Chak 2022 年 3 月 12 日
Have you double checked the mathematical equations of your system? Since you didn't tell us what kind of system it is, and your supplied ODEs have been verified by the ode45 solver, there seems nothing wrong with the program itself. If you are very sure that the system is stable, then my guess is that one or more of the terms in the state equations must be the root cause of the instability.
Jan
Jan 2022 年 3 月 12 日
@Sam Chak: Thanks for your effort. If a user ignores your help consequently, this is his problem.

サインインしてコメントする。

カテゴリ

製品

リリース

R2021b

タグ

質問済み:

2022 年 3 月 11 日

コメント済み:

Jan
2022 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by