Jan-18-2021, 11:38 AM
(This post was last modified: Jan-18-2021, 11:38 AM by edwinostby.)
Hey, I have an assignment due this week. The given task is to solve a differential equation by using Euler's method, the task is;
Solve the differential equation, f'(t) = 4 + 3 * f(t), with t ∈ [0,2], by using Euler's method. Thereafter plot the solution. Use f(0) = 0 as initial condition. Use 10 000 steps.
This is the code that ive come up with so far, but i cant find a solution to the error given. Currently on windows 10, 64-bit using python 3.8.5.
Solve the differential equation, f'(t) = 4 + 3 * f(t), with t ∈ [0,2], by using Euler's method. Thereafter plot the solution. Use f(0) = 0 as initial condition. Use 10 000 steps.
This is the code that ive come up with so far, but i cant find a solution to the error given. Currently on windows 10, 64-bit using python 3.8.5.
import numpy as np from matplotlib import pyplot as plt def derived_f(t, ft): return(4 + 3 * f(t)) t0 = 0 f0 = 0 t_end = 2 N = 10000 h = (t_end - t0) / (N - 1) t = np.linspace(t0, t_end, N) f = np.zeros(N) f[0] = f0 for i in range(N - 1): f[i + 1] = f[i] + derived_f(t[i]) * h plt.plot(t, f) plt.title("Title") plt.xlabel("xlabel") plt.ylabel("ylabel")
Error:TypeError: derived_f() missing 1 required positional argument: 'ft'