So for my assignment I have to code a program to solve first order ODE's using Euler's Method. My program works, it returns the right values. (I checked using an online calculator). However, solution to the assignment returns something very different.
The initial condition is x(0) = 0, from t = 0 to t = 10. With 10 steps. (I presume it to be the green line)
Using my program I get the results: ([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], (the x values)
And the y-values respectively
So as you can see, in the solutions, the y values don't even go as far as -1.0. So I'm wondering how does this happen?
EDIT CODE: f = function y0 = initial condition at time t0 t0 = initial time h = step size N = number of steps
def integrateEuler(f,y0,t0,h,N): t = t0 y = y0 z =  v =  yf = N*h #final xval while t <= N: xval = t yval = [y] t += h y += h * f(t,y) z.append(xval) v.append(yval) return z, v #FUNCTION def f(x,t): vv = -x**3 - x + sin(t) return vv
I enter in the shell:
>>>Euler(f, 0., 0., 1., 10)
f(x,t), but you call
f(t,y). Switch the order of arguments in either call or definition. $\endgroup$