Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 ( a ) Write a function that implements the following pseudo - code: Input: f , f ' , x , l o
Question
a Write a function that implements the following pseudocode:
Input:
Output:
Repeat times:
a Set
b Take one Newton step, starting from Call the result
c Take one Newton step, starting from Call the result
d Set
e Display
f If print "converged!", break.
Output
This algorithm is called Steffensen's iteration.
b Test your routine on the problem
exp initial guess
Show that Newton iteration does not converge quadratically, but your new iterative algorithm
does.
steff.
import numpy as np
def steffffpxepse,epsr,itmx:
# Steffensen iteration for fx
# Input: function handles f and f floats inital guess x tolerance for error epse and residual epsr integer max nur of iterations itmx.
# Output: approximate solution x estimate of error, residual.
initializations
for i in range: # Loop over iterations.
if : # Check for convergence.
if # Print warning message if there was no convergence.
print
return xerr,res # Return floats: approximate root x approximate error err and residual res.
cript.
import numpy as np
from steff import steff
from newton import newton
# Question
def fx:
return
def fpx:
return
# Find reasonable values for residual and error tolerance and the number of iterations:
tolerr
tolres
itmax
# initial point
x
# First try Newton iteration:
printCalling Newton function..."
xerr,res newton
# That converges slowly, now try steffenson
printCalling Steffensen function..."
xerr,res steff
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started