22/10/2019 Problem5NewtonRaphsonMethod
Problem 5: Newton-Raphson Method
localhost:8891/nbconvert/html/[Link]?download=false 1/3
22/10/2019 Problem5NewtonRaphsonMethod
In [23]: import [Link] as plt
import numpy as np
if __name__ == "__main__":
def function(x):
return (9.8*x/14)*(1 - [Link](-1*14*10.22/x)) - 48.7564 # The main fun
ction
def derivative(x):
return (9.8/14)*(1 - ([Link](-1*14*10.22/x)*(1 + (14*10.22/x)))) # The
derivative
def newton(function, derivative, x0, tolerance, number_of_max_iterations=100):
x1 = 0
if abs(x0-x1)<= tolerance and abs((x0-x1)/x0)<= tolerance:
return x0
print("k\t x0\t\t function(x0)")
k = 1
while k <= number_of_max_iterations:
x1 = x0 - (function(x0)/derivative(x0))
print("x%d\t%e\t%e"%(k,x1,function(x1)))
if abs(x0-x1)<= tolerance and abs((x0-x1)/x0)<= tolerance:
[Link](x0, function(x0), 'or')
return x1
x0 = x1
k = k + 1
[Link](x0, function(x0), 'or')
# Stops the method if it hits the number of maximum iterations
if k > number_of_max_iterations:
print("ERROR: Exceeded max number of iterations")
return x1 # Returns the value
F = newton(function, derivative, 1.7, 0.0000001)
print("The approximate value of x is: "+str(F))
# Plotting configuration
u = [Link](1.0, 2.0, 0.0001) # Setting up values for x in the plot
w = (9.8*x/14)*(1 - [Link](-1*14*10.22/x)) - 48.7564 # Define the main functio
n again
[Link](u, w)
[Link](y=0.0, color='black', linestyle='-')
[Link]('Newton-Raphson Graphics for' + ' y = (9.8*x/14)*(1 - [Link](-1*14*1
0.22/x)) - 48.7564')
[Link]('X')
[Link]('Y')
[Link](True)
[Link](['Xn'], loc='upper left')
[Link]()
localhost:8891/nbconvert/html/[Link]?download=false 2/3
22/10/2019 Problem5NewtonRaphsonMethod
k x0 function(x0)
x1 6.965200e+01 -6.250266e+00
x2 8.432646e+01 -5.466393e-01
x3 8.587055e+01 -5.180202e-03
x4 8.588547e+01 -4.755761e-07
x5 8.588547e+01 0.000000e+00
x6 8.588547e+01 0.000000e+00
The approximate value of x is: 85.88546897608387
Since m = 85.88 from above, the actual mass now is
mparatroopper = mderived - 5kg mparatroopper = 85.88 - 5 mparatroopper = 80.88 kg
localhost:8891/nbconvert/html/[Link]?download=false 3/3