Question: Both Exercises are needed in Python. I went ahead and added both the bisection and secant method functions under each exercise. I keep running across
Both Exercises are needed in Python.
I went ahead and added both the bisection and secant method functions under each exercise. I keep running across errors when I try to implement my code so please help.
EXERCISE
Define a lambda function that represents a cubic polynomial:yxxxx
Use this lambda function to generate y values for x values ranging from to inclusivewith an increment of
Use the bisectionmethod function defined above to solve the root in the braket of with the default stopping criteria value.
Create a line plot to visualize the cubic function.
Add appropriate labels for the xaxis and yaxis, a title for the plot, and a grid for better readability.
Mark the root in the plot.
#EXAMPLE
def bisectionmethodf a b ese:
import numpy as np
i
cab #first guess
ea
if fafb:
return 'initial interval does not include solution'
# iterative
while eaes:
if fafc:
ac
else:
bc
ii
oldc #save old guess
cab #new guess
eaabscoldc #relative error
printceai
return c
printThe root lies at c
EXERCISE
Define a lambda function that represents a cubic polynomial:yxxxx
Use the lambda function to generate y values for x values ranging from to inclusivewith an increment of
Use the secantmethod function defined above to solve the root in the braket of with the default stopping criteria value.
Create a line plot to visualize the cubic function.
Add appropriate labels for the xaxis and yaxis, a title for the plot, and a grid for better readability.
Mark the root in the plot.
#EXAMPLE
def secantmethodf x x ese maxiter:
# Implements the Secant Method to find the root of a function f
# Parameters:
# f : function, the mathematical function for which to find the root
# x x : float, initial guesses
# es : float, tolerance for convergence default: e
# maxiter : int, maximum number of iterations default:
# Returns:
# x : float, the approximated root
#initialze
ea
i
while eaes and i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
