Math 223 Current Assignment

Comments on Problem 2.7.8 page 245

The program newton.m assumes its first two arguments are vectors (not matrices) of the same length. So iIf you wish to use the newton program in appendix B on page 669, you will need to convert 3 by 3 matrices to 9 by 1 vectors.

The first argument should be a vector of symbolic expressions in the varaibles, x1, x2, etc. These names of variables are hardcoded in the routine, so others are not likely to work.

Entry of symbolic expressions in Matlab is delicate; sometimes an extra space will break the syntax. (Symbolic expressions are often represented as strings.) You can construct a suymbolic 3 by 3 matrix with entries x1, x2, etc. by

	G = sym('[x1,x2,x3; x4, x5, x6; x7 x8 x9]')
Such a matrix could for example be symbolically cubed by G*G*G.

You can reshape a 3 by 3 matrix B into a 9 by 1 vector using the command

	reshape(B,9,1)
or reshape a 9 by 1 matrix C into a vector by
	reshape(C,3,3)

The following text of newton.m is taken from the Student Matlab folder on Ontario and does work. As described in Hubbard and Hubbard, typical usage is

	syms x1 x2
	newton([cos(x1)-x1; sin(x2)], [.1; 3.0], 3)

Text of newton.m

function [x]=newton(F,x0,iterations)
vars='[';
for i=1:length(F)
  iS=num2str(i);
  vars=[vars 'x' iS ' '];
  eval(['x' iS '=sym(''x' iS ''');']);
end
vars=[vars ']'];
eval(['vars = 'vars ';']);
J=jacobian(F,vars);
x=x0;
for i=1:iterations
  JJ=double(subs(J,vars,x.'));
  FF=double(subs(F,vars,x.'));
  x=x-inv(JJ)*FF
end
Last Update: October 30, 1998