'How to make this code to print out the result?
import math
import numpy as np
import matplotlib.pyplot as plt
def F(x):
return x**5/(np.exp(x)-1)
def deriv(x):
a=0.0001
return (F(x+a)-F(x))/a
def newton_step(xi):
return (xi-F(xi)/deriv(xi))
def newton(x0):
list_of_approx=[]
error=1
while error>pow(10,-6):
xnext=newton_step(x0)
error=abs(xnext-x0)
list_of_approx.append(xnext)
xo=xnext
return list_of_approx
def main():
step=1
initial_guess=float(input("Please give initial guess:"))
list_of_approx=newton(initial_guess)
for i in list_of_approx:
print("Approx"+str(step)+" = "+str(i))
step=step+1
main()
My code is to find the root of the first derivative of F(x) with newton's method.When I input the initial guess of 5,it cannot print out the result.Plz help me to fix My code!Thx!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
