DOC PREVIEW
Berkeley MATH 128A - Math 128A Programming Assignment

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Prof. Ming Gu, 861 Evans, tel: 2-3145Office Hours: WF 2:00-3:000PMEmail: [email protected]://www.math.berkeley.edu/∼mgu/MA128A2010FMath128A: Numerical AnalysisProgramming Assignment #1, Due 9/29/2010Consider the cubic equationax3+ bx2+ cx + d = 0, (1)where a 6= 0, b, c, and d are random constants.1. Compute the roots using the exact formulas for the roots of equation (1). For this write afunction .m file with the format[roots] = cubic(a, b, c, d),where a, b, c, d are the coefficients of the cubic polynomial input. This function should returna vector with the three roots of the cubic, sorted using the Matlab sort() function.2. To solve equation (1) with numerical methods, for each of the bisection method, Newton’smethod, and the Muller’s method, you should(a) First compute a root of equation (1) using each of the methods listed. Do this bycreating function .m files with the formats[root] = bisection(a, b, c, d),[root] = newton(a, b, c, d),[root] = muller(a, b, c, d),where a, b, c, d are the coefficents of the cubic. Use relative change in iteration, |pn+1−pn|/|pn| as a measure of error, and tolerance 10−6, except in bisection method, whereyou should use |f(pn)| instead. Be sure to use the function .m file template and includesome comments about how your function works.(b) Use deflation procedure to reduce equation (1) to a second order equation. Do thisby creating a function [A, B, C] = deflate(a, b, c, d, root), where a, b, c, d are the co-efficients of an input cubic, root is a root of the cubic, and the outputs A, B, C arecoefficients of a quadratic polynomial with the same roots as the input cubic, exceptroot.Math128A: Numerical Analysis, Programming Assignment #1, Due Sept. 29, 2010 2(c) Solve the second order equation. To do this make a function[roots] = quadratic(a, b, c),that finds the roots of the quadratic ax2+ bx + c = 0 using the quadratic equation.3. Add more input arguments as necessary (such as initial interval for bisection and initial guessfor other methods.) Your initial guesses do not have to be very robust for this assignment.4. Compare the accuracy of roots computed using the exact root formulas and the abovenumerical methods with those obtained with the roots matlab command. Do this for 100random cubic polynomails, and report the average and maximum differences between yourroots and those of roots.Write a script .m file called testrootfinders.m that calls your functions cubic, bisection,newton, muller, deflate, quadratic as well as the Matlab command roots and returnsthe results requested above. To generate random coefficients a, b, c, d you can use the rand()function. To check the difference between approximate and exact roots, you can usenorm(exactroots − approximateroots).Have the script file print each of the results in such a way that we can tell what they are.Make sure that your vectors of exact roots and approximate roots are both sorted when youcompare them!Important: The names, inputs, and outputs of all the functions and scripts you write must beexactly as written above. This includes capitalization of .m file names and order of inputs andoutputs. If not, we cannot grade your


View Full Document
Download Math 128A Programming Assignment
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Math 128A Programming Assignment and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Math 128A Programming Assignment 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?