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
#8
One step to a solution is understanding the Euler method.
The idea is to numerically calculate a decent approximation of something that otherwise can be quite difficult. You want to approximate as closely as possible the function f by only knowing the relation between the function and its first derivative. You have a starting point, in this case 0 and an end point (here 2). The idea is that this is enough if you can find an accurate point on the function close to the starting point in order to approximate the slope of the curve with that of a secant and thus be able to find another point of the curve. Then use that point to recalculate the slope in that point and so on until you reach the endpoint.
(The image is just to show the idea, it is not closely related to the function in the given problem).
[Image: 345px-Derivative.svg.png]
It is obvious that the approximation gets better if h is very small. Euler showed that if it is small enough then you can stepwise approximate the derivative and thus the whole function (and in many cases find the function f very accurately, especially in the case of first order differential equations). In the current case I think that the problem is a suitable introductionary problem to illustrate the Euler method.

The normal case for the Euler method is in general terms (I use "g" to avoid confusion with the given problem. I could use any letter to denote "some function")

y' = g(x,y)

Translated to the given problem it gives us

f'(t) = g(t, f(t)) => f'(t) = 4 + 3*f(t)

As there is no other dependency on "t" apart from "f(t)", which is replaced by a stepwise calculated constant the rule becomes quite simple when we translate it into the Euler formula

yn+1 = yn + f'(yn) * (tn+1 - tn)

which gives us

f(t1) = f(t0) + (4 + 3*f(t0)) * h

The start values are given: t0 = 0 and f(t0) = 0 (implicitly from the interval given as t ∈ [0,2] and f(0) = 0. Use 10 000 steps tells us that h = 2 / 9999 = 0.00020002...
Take two steps (to test it, I approximate h to 0.0002):

f[0] = 0
f[1] = f[0] + derived_f(f[0]) * h = 0 + derived_f(0) * 0.0002 = 0 + 4 * 0.0002 = 0.0008
f[2] = 0.0008 + derived_f(0.0008) * h = 0.0008 + (4 + 3 * 0.0008) * 0.0002 = 0.00160048
...

So, the absence of t in f'(t) simplifies the problem and only one parameter is needed in "derived_f" ("df" would be a better name in my opinion).
Reply


Messages In This Thread
RE: Missing 1 required positional argument in python code - by Serafim - Jan-19-2021, 12:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: __init__() missing 1 required positional argument: 'successor siki 1 4,355 Mar-08-2021, 02:05 PM
Last Post: Larz60+
  Missing positional arguments error?? hhydration 2 2,189 Oct-01-2020, 05:33 AM
Last Post: buran
  TypeError: Missing required positional arguments liaisa 7 29,358 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,718 Dec-18-2019, 06:59 AM
Last Post: akashraj128
  missing positional argument error programmert 1 2,855 Oct-18-2019, 11:05 AM
Last Post: Larz60+
  missing 1 required positional argument jedmond2 4 6,797 Sep-19-2019, 12:00 PM
Last Post: jefsummers
  missing 1 required positional argument mcgrim 10 19,931 May-07-2019, 09:02 PM
Last Post: Yoriz
  TypeError: __init__() missing 3 required positional arguments Pythonhelp82 6 23,263 Jan-24-2019, 04:25 AM
Last Post: Pythonhelp82
  TypeError: method missing 1 positional argument koolinka 4 5,110 Nov-18-2018, 04:53 PM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,264 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