numerical - COMPUTER SCIENCE 349A ASSIGNMENT #4 DUE MONDAY...

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

View Full Document Right Arrow Icon
COMPUTER SCIENCE 349A ASSIGNMENT #4 DUE MONDAY FEBRUARY 6, 2012 (in class) 1. (a) Write a MATLAB function M-file for Newton’s method corresponding to the following pseudocode: converge to failed output while end root x i i if end exit root x if root i output x f x f x root while i heading output i ) ε , , x newton ( oot function r + < = 0 0 0 0 0 0 1 / 1 , ) ( / ) ( imax 1 imax ε Use the following (or similar) MATLAB print statements. fprintf ( ‘ iteration approximation \n’) fprintf ( ‘ %6.0f ‘, i ), fprintf ( ‘%18.10f \n’, root ) fprintf ( ‘ failed to converge in %g ‘, imax ), fprintf (‘ iterations \n ‘ ) HAND IN a copy of your MATLAB M-file. (b) An oscillating current in an electric circuit is described by ) 2 cos( 9 t e i t π = , where t is in seconds. Determine all positive values of t such that i = 3.5 . The solution to this problem can be posed as determining the positive zeros of a function ) ( x f . Careful analysis of the graph of the function ) ( x f shows that ) ( x f has only one positive zero, and it is in the interval [0, 1]. Use the MATLAB function M-file newton with 6 0 10 , 1 . 0 = = x and imax = 20 to solve the above problem. Note that in MATLAB, 6 10 is 1e-6 (not 10e-6). Note. You will need to write MATLAB function M-files with headers something like
Background image of page 1

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

View Full DocumentRight Arrow Icon
function y = f(x) and function y = fp(x) corresponding to the function ) ( x f that you are computing a zero of, and its derivative ) ( x f . Note. HAND IN a printed copy of your M-files f and fp , as well as the output from newton . (c) Although the above function ) ( x f has only one positive zero, it has many negative zeros. The use of Newton’s method to compute the positive zero is very sensitive the choice of an initial condition. Show this by using newton as follows: with 6 0 10 , 5 . 0 = = ε x and imax = 20 and with 6 0 10 , 9 . 0 = = x and imax = 20 . (d) Use the MATLAB function ezplot to draw a graph of the function ) ( x f used in (b) and (c) on the interval ] 2 3 [ . The following MATLAB statement illustrates the syntax of ezplot : ezplot(‘exp(-x)+cos(pi*x)’, [ 1 5 ] ) will cause a graphics window to open and will display the graph of the function ) cos( x e x π + on the interval [ 1 5 ]. Under ' file ' in this window, select ' print ' in order to print it. PRINT and HAND IN the graph of ) ( x f .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/15/2012 for the course ECON 202 taught by Professor Paul during the Spring '12 term at Université Toulouse III Paul Sabatier.

Page1 / 5

numerical - COMPUTER SCIENCE 349A ASSIGNMENT #4 DUE MONDAY...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online