Docsity

Multivariable Calculus - Assignment | MATH 340, Assignments of Calculus

Toggle sidebar
bg1
MATH 340 Sec. 0101
Computer Assignment 2: MATH 340, Fall 2008
Due Friday, November 7
You may work in groups of up to three people. Each group must submit a single printed solution. Solutions must
contain your relevant MATLAB input and output (do not include commands that didn’t work), and text that indicates
what your commands are doing and interprets your results. (You may find one of the following commands useful in
preparing your solutions: publish,notebook, or diary; see MATLAB’s online help for details.) Organization
and clarity count.
.................................................................................................
Newton’s method, discussed in Section 2.4 of Colley’s book, approximates solutions of a system of n
equations in nunknowns. It requires an input vector that represents an initial guess, and iteratively produces
a sequence of vectors that, if all goes well, converge to a solution. The following simple MATLAB program
performs Newton’s method in R2.
function z = newton(func, z0, iter)
syms x y
deriv = jacobian(sym(func), [x y]);
z = z0;
for n = 1:iter
D = double(subs(deriv, {x,y}, z));
F = double(subs(func, {x,y}, z));
z = z - inv(D)*F;
end
To use this program, download it from the class web page or type it into a file called newton.m in your
MATLAB working directory. Then, for example, to perform 5iterations of Newton’s method on the system
x+y= 1
x2+y2= 2
with initial guess x= 1,y= 0, you can type:
newton(’[x + y - 1; xˆ2 + yˆ2 - 2]’, [1;0], 5)
You can leave out the quotes if you type syms x y beforehand, but you must include the semicolons
to make both the function and the initial guess be column vectors. The output is a single column vector
representing the 5iteration; if you want to see the intermediate iterations as they are computed you can
delete the last semicolon from the program newton.m.
This assignment concerns the problem of solving the system of equations:
x= 8 cos(x+y)
y3= 12 sin(x+y)
(a) Try the following command to solve the system of equations using the symbolic command
solve:
Fall 2008 1 B. Hunt
pf2

Partial preview of the text

Download Multivariable Calculus - Assignment | MATH 340 and more Assignments Calculus in PDF only on Docsity!

MATH 340 Sec. 0101

Computer Assignment 2: MATH 340, Fall 2008

Due Friday, November 7

You may work in groups of up to three people. Each group must submit a single printed solution. Solutions must contain your relevant MATLAB input and output (do not include commands that didn’t work), and text that indicates what your commands are doing and interprets your results. (You may find one of the following commands useful in preparing your solutions: publish, notebook, or diary; see MATLAB’s online help for details.) Organization and clarity count.

................................................................................................. Newton’s method, discussed in Section 2.4 of Colley’s book, approximates solutions of a system of n equations in n unknowns. It requires an input vector that represents an initial guess, and iteratively produces a sequence of vectors that, if all goes well, converge to a solution. The following simple MATLAB program performs Newton’s method in R^2.

function z = newton(func, z0, iter) syms x y deriv = jacobian(sym(func), [x y]); z = z0; for n = 1:iter D = double(subs(deriv, {x,y}, z)); F = double(subs(func, {x,y}, z)); z = z - inv(D)*F; end

To use this program, download it from the class web page or type it into a file called newton.m in your MATLAB working directory. Then, for example, to perform 5 iterations of Newton’s method on the system

x + y = 1 x^2 + y^2 = 2

with initial guess x = 1, y = 0, you can type:

newton(’[x + y - 1; xˆ2 + yˆ2 - 2]’, [1;0], 5)

You can leave out the quotes if you type syms x y beforehand, but you must include the semicolons to make both the function and the initial guess be column vectors. The output is a single column vector representing the 5 iteration; if you want to see the intermediate iterations as they are computed you can delete the last semicolon from the program newton.m.

This assignment concerns the problem of solving the system of equations:

x = 8 cos(x + y) y^3 = 12 sin(x + y)

(a) Try the following command to solve the system of equations using the symbolic command solve:

Fall 2008 1 B. Hunt

MATH 340 Computer Assignment 2 Sec. 0101

[x y] = solve(’x = 8cos(x+y)’, ’yˆ3 = 12sin(x+y)’) This command can sometimes find exact formulas for all the solutions to a system of equations, but when it can’t it tries to solve them numerically. Check to see that the output of this command really is (at least approximately) a solution of the equations. (b) Try the Newton’s method program above using the initial guess x = y = 0 to solve the system. Type format long to display more decimal places, and show the results of 1 iteration, 2 iterations, 3 iterations, and so on, until two successive iterations agree to all decimal places shown. At what point do the iterations start getting close to the final answer? Once they get close, how quickly does their accuracy improve? (Quantify in some way your answer to this question.) (c) Now try to find accurate approximations to all solutions of the system. You will have to try different initial guesses to get different solutions. Since you don’t know in advance how many solutions there are or even how big they may be, it can be hard to find them all by trial-and-error. Think about how big the solutions can possibly be, in order to determine a reasonable range for initial guesses. Graphing the equations can be helpful too. In your final report, please only include one initial guess for each solution you find, and describe how you came up with those initial guesses.

Fall 2008 2 B. Hunt