EMHPM plot function by multisteps

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by