MATLAB: EMHPM plot function by multisteps

MATLABplot in multistages

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

Best Answer

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!