Hi, I am trying to solve the ODE dydt = 56t using euler in Matlab
The code below gives me x and y values, however they are in the form of horizontal matrices as opposed to vertical and when I try to change the matrice to vertical ( using t = 0;h;0.5; ) it tells me that the vectors are not the same length. Nothing also shows up in the plot generated. Does anybody know where I am going wrong? Thanks.
Also if I wanted to add in the exact solution to compare with the Euler method. How would I add that in and plot it?
The exact solution may be calculated by,
f = @(x)exp(x^2/2);
My code is,
y0 = 0;
h = 0.1;
t = 0:h:5;
N = length(t);
y_euler = zeros(size(t));
y_euler(1) = y0;
dydt = @(t,y) 56*t;
k1 = dydt(t(i),y_euler(i));
y_euler(i+1) = y_euler(i) + h*k1;