Python Forum
Missing 1 required positional argument in python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing 1 required positional argument in python code
#1
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.

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'
Reply


Messages In This Thread
Missing 1 required positional argument in python code - by edwinostby - Jan-18-2021, 11:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: __init__() missing 1 required positional argument: 'successor siki 1 4,321 Mar-08-2021, 02:05 PM
Last Post: Larz60+
  Missing positional arguments error?? hhydration 2 2,161 Oct-01-2020, 05:33 AM
Last Post: buran
  TypeError: Missing required positional arguments liaisa 7 29,087 Sep-25-2020, 08:16 PM
Last Post: deanhystad
  How to Use Python for solving the following physics question. Python Code required ishahid 8 3,652 Dec-18-2019, 06:59 AM
Last Post: akashraj128
  missing positional argument error programmert 1 2,829 Oct-18-2019, 11:05 AM
Last Post: Larz60+
  missing 1 required positional argument jedmond2 4 6,718 Sep-19-2019, 12:00 PM
Last Post: jefsummers
  missing 1 required positional argument mcgrim 10 19,831 May-07-2019, 09:02 PM
Last Post: Yoriz
  TypeError: __init__() missing 3 required positional arguments Pythonhelp82 6 23,162 Jan-24-2019, 04:25 AM
Last Post: Pythonhelp82
  TypeError: method missing 1 positional argument koolinka 4 5,048 Nov-18-2018, 04:53 PM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,223 Nov-16-2018, 07:18 PM
Last Post: itmustbebunnies

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020