Help with Euler's method?
Afficher commentaires plus anciens
Consider the initial Value Problem: dy/dt=y(2-ty), y(0)=1 Use Euler's method to determine the approximate values of the solution at t=1,1.5,2,2.5 with grid sizes a)h=0.01, b)h=0.05, c)h=0.10. List results in Tabular form.
So i been trying to work on this for a while but having a lot of trouble. Any help will be greatly appreciated. Here's what I have so far:
function dy = f(t,y)
dy=(2*y)-(t*(y^2));
t0=0;
y0=1;
t1=1;
tf=2.5;
n=150
h=(tf-t1)/n
t=t1;
y=y0;
T=t;
Y=y;
for i = 1 : n % for i = 1 to n do
k = f(x,y); % the left-hand slope
y = y + h*k; % Euler step to update y
x = x + h; % update x
X = [X; x]; % adjoin new x-value
Y = [Y; y]; % adjoin new y-value
end
[X,Y]
[X(n-120), Y(n-120)]
[X(n-135), Y(n-135)]
Réponses (0)
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!