# EMHPM plot function by multisteps

2 views (last 30 days)
Jose Sosa Lopez on 11 Feb 2020
Commented: Jose Sosa Lopez on 14 Feb 2020
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
Jose Sosa Lopez on 14 Feb 2020
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.
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 on 14 Feb 2020
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!

R2019b

### Community Treasure Hunt

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

Start Hunting!