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
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)
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 endLast Update: October 30, 1998