{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Solution-HW2

# Solution-HW2 - 1 Write a program in a language of your...

This preview shows pages 1–3. Sign up to view the full content.

1 Write a program in a language of your choice to implement Newtons method. Assume that you have functions f(x) and fp(x) to return the function value and its derivative. Try out the Newtons method program to find a root of ( ) x e x f x = ) 2 / ( 2 . SOLUTION: Option Explicit Function Newton(xi, es, imax) Dim xr As Double, xrold As Double, ea As Double, xinc As Double Dim iter As Integer iter = 0 xr = xi Do xrold = xr iter = iter + 1 xinc = -f(xr) / fp(xr) xr = xrold + xinc If xr <> 0 Then ea = Abs((xr - xrold) / xr) End If If (ea < es) Or (iter >= imax) Then Exit Do End If Loop Newton = xr MsgBox ("ea = " & ea & " iter = " & iter) End Function Function f(x) f = Exp(-(x ^ 2) / 2) - x End Function Function fp(x) fp = -x * Exp(-(x ^ 2) / 2) - 1 End Function INPUT: Initial guess: x i =1 Percent tolerance: es=0.001 Iterations: imax=100 OUTPUT: Root: x r =0.753089165 Relative percent error: ea=5.447936E-7 Interation: I=3 5.2 Determine the real roots of ( ) 3 2 6 5 7 2 x x x x f + + = :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
(a) Graphically. (b) Using bisection to locate the lowest root. Employ initial guesses of x l =0 and x u =1 and iterate until the estimated error ε a falls below a level of ε s =10%. SOLUTION: (a) (b) Bisection method: Starting with x l =0, x u =1 . We know 2 u l r x x x + = , % 100 × + = l u l u a x x x x ε . Make sure ( ) ( ) 0 < u l x f x f in every iteration. The results are: Interation x r Ε a % 1 0.5 100 2 0.25 100 3 0.375 33 4 0.3125 22 5 0.34375 9.1 5.3 Determine the real roots of ( ) 5 4 3 2 65 . 0 9 4 . 45 88 3 . 82 26 x x x x x x f + + + = : (a) Graphically.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern