EMHPM plot function by multisteps

1 回表示 (過去 30 日間)
Jose Sosa Lopez
Jose Sosa Lopez 2020 年 2 月 11 日
コメント済み: Jose Sosa Lopez 2020 年 2 月 14 日
Hello, could you help me to know how can I plot this kind of function, I want to plot by steps, the value of Y when t=0, t=0.1, t=0.2, and so on, but using in the next Y the value of the previous one.
The function that I did is:
clear all; clc;
t=0;
T=0;
c=1;
yi0=c;
while t<=(10)
t
yi1=(T/1)*(yi0*-exp(t)*yi0*yi0);
yi2=(T/2)*(yi1*exp(t)-exp(t)*yi1*yi0);
yi3=(T/3)*(yi2*exp(t)-exp(t)*yi2*yi1);
Y=yi0+yi1+yi2+yi3;
yi0=Y
plot (t,Y) %(I dont know how to plot it)
t=t+0.1;
T=0.1;
end
  1 件のコメント
Jose Sosa Lopez
Jose Sosa Lopez 2020 年 2 月 14 日
yes, Thank you. That's what I was looking for.
I also solve it, although I mistake in the equation, but I agree with your answer.
Thanks for your time.
clear all; clc; close all;
T=0;
c=1;
yi0=c;
t=linspace(0,10,101); Y=t;
Y(1)=yi0;
T=0.1;
for ite=2:101
% % % for t=0:5
yi1=(T/1)*(yi0-exp(t(ite))*yi0^2);
yi2=(T/2)*(yi1-exp(t(ite))*yi1*yi0);
yi3=(T/3)*(yi2-exp(t(ite))*yi2*yi1);
Y(ite)=yi0+yi1+yi2+yi3;
yi0=Y(ite);
end
plot(t,Y','--')
hold on
t=linspace(0,10,101);
yinicial = 1;
[t,y] = ode45(@(t,y) y-(exp(t))*y^2, t, yinicial);
plot (t,y)
hold off

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

採用された回答

Payas Bahade
Payas Bahade 2020 年 2 月 14 日
Hi Jose,
I have used array ‘tp’ and ‘Yp’ to store values of ‘t’ and ‘Y’ respectively for evey time step and used it to make the final plot. Below mentioned is the modified code:
t=0;
T=0;
c=1;
yi0=c;
i=1;
while t<=10
tp(i)=t; % storing t values
yi1=(T/1)*(yi0*-exp(t)*yi0*yi0);
yi2=(T/2)*(yi1*exp(t)-exp(t)*yi1*yi0);
yi3=(T/3)*(yi2*exp(t)-exp(t)*yi2*yi1);
Y=yi0+yi1+yi2+yi3;
yi0=Y;
Yp(i)=Y; % storing Y values
t=t+0.1;
T=0.1;
i=i+1;
end
plot(tp,Yp) % plotting all t and Y values
xlabel('t')
ylabel('Y')
Output:
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by