﻿# forwards Euler

a = 0;   b = 10;
n = 100;

f = @(t,y) 2*y - t*y - 1;
y0 = 0;

# compute h
h = (b-a)/(n-1);

# sample points
t = a : h : b ;

# vector for solution
y = zeros(1, length(t));

# Euler's method
for (i = 1 : length(t)-1)
    y_prime = f(t(i), y(i));
    y(i+1)  = y(i) + h*y_prime;
end

# plot answer
plot(t, y)

