This document provides an example of using multidimensional Newton's method to find the root of a function. It defines a sample function that returns both the value and Jacobian matrix of two variables. It then defines a Newton's method function that takes the sample function and initial point and iterates to find the root. Running it for a few iterations on the sample function starting at [1;2] returns a result close to the known solution.
This document provides an example of using multidimensional Newton's method to find the root of a function. It defines a sample function that returns both the value and Jacobian matrix of two variables. It then defines a Newton's method function that takes the sample function and initial point and iterates to find the root. Running it for a few iterations on the sample function starting at [1;2] returns a result close to the known solution.
This document provides an example of using multidimensional Newton's method to find the root of a function. It defines a sample function that returns both the value and Jacobian matrix of two variables. It then defines a Newton's method function that takes the sample function and initial point and iterates to find the root. Running it for a few iterations on the sample function starting at [1;2] returns a result close to the known solution.
Here is the textbook example, written out in a couple of files.
First, the function (whose root we are trying to find) is written. The point to notice here is that we output not just the value of the function, but also its Jacobian matrix: function [y dy]=myfunction(x) %Example function to try out Newtons Method % n=length(x); y=zeros(size(x)); %Not necessary for a small vector dy=zeros(n,n); %Not necessary for a small matrix y(1)=-x(1)^3+x(2); y(2)=x(1)^2+x(2)^2-1; dy(1,1)=-3*x(1)^2; dy(1,2)=1; dy(2,1)=2*x(1); dy(2,2)=2*x(2); Next, we write a little Newtons Method function: function x=multinewton(f,x,NumIters) %Performs multidimensional Newtons method for the function defined in f %starting with x and running NumIters times. [y,dy]=f(x); for j=1:NumIters s=dy\y; x=x-s; [y,dy]=f(x); end And here is the output, using a couple of iterations (compare with step 8 of the table on page 134): >> format long >> x=[1;2]; >> y=multinewton(@myfunction,x,7); >> y ans = 0.826031357654187 0.563624162161259