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 CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by