Question: How could this newton's method code be improved to add more functionality and also have an aesthetic user friendly interface with a dashboard showing giving

How could this newton's method code be improved to add more functionality and also have an aesthetic user friendly interface with a dashboard showing giving the user the option to input their values for a, b, c, w, v? The graph plotted also should be extended to include the dots of the solutions. Show the new and improved code in its entirety
import numpy as np
import matplotlib.pyplot as plt
# Define the function based on the equation: f(x)= ax^b - e^(cx)* sin(wx + v)
def f(x, a, b, c, w, v):
return a*(x**b)-(np.exp(c*x))*np.sin((w*x)+v) #f(x)
# Define the derivative of the function with respect to x
def fderx(x, a, b, c, w, v):
return (a*b*(x**(b-1)))-(np.exp(c*x)*(np.sin((w*x)+v)*c + np.cos((w*x)+v)*w)) #f'(x)
def newtons_method(a,b,c,w,v,x0,tolerance=1e-7):
x=x0
for i in range(100):
fx= f(x, a, b, c, w, v)
fpx=fderx(x, a, b, c, w, v)
if fpx==0:
print("The derivative is equal to zero, no solution found")
return None
x_new = x-fx/fpx
if abs(x_new-x)< tolerance:
return x_new
x=x_new
print("Exceeded maximum iterations. No solution found.")
return None
def multSolns(a, b, c, w, v, initial_guesses):
solutions=[]
for x0 in initial_guesses:
solution=newtons_method(a,b,c,w,v,x0)
if solution is not None:
#if solution not in solutions:
if all(abs(solution - s)>1e-5 for s in solutions):
solutions.append(solution)
return solutions
initial_guesses =[-10,-5,0,5,10]
#a, b, c, w, v =1,2,-0.5,1.5,0.5
a=float(input("Please enter a number for a: "))
b=float(input("Please enter a number for b: "))
c=float(input("Please enter a number for c: "))
w=float(input("Please enter a number for w: "))
v=float(input("Please enter a number for v: "))
solutions = multSolns(a, b, c, w, v, initial_guesses)
print("Found solutions:", solutions)
t= np.arange(-10,10,.01)
plt.plot(t,f(t, a, b, c, w, v))
plt.grid(True)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!