I'm trying to use a Jacobian to solve an equation using the Newton Raphson method but I keep getting a type 'double' error. Symbolic is installed as well. I am wondering if I am using F correctly here. Do I have to use the Jacobian separately for F(1) and F(2)? Here is the script:
X=[0.75 0.25]; %N-dimensional array, first guess then solution
Y=[0 0];
F(1)=(X(1)^2)+(X(2)^2)-1; %right hand side functions
F(2)=X(1)+X(2)-1; %right hand side functions
MAXIT=10;
ITEST=1;
counter=0;
ABSER=0.00001;
RELER=.1;
DFDX=jacobian(F,X);
[X,ITEST,counter] =NLNR(X,F,MAXIT,counter,ABSER,RELER,ITEST,DFDX);
fprintf('answer for X1 is %d and X2 is %d and ITEST is %d.\n',X(1),X(2),ITEST);
fprintf('number of interations is %d.\n',counter);
and this is the function:
function [X,ITEST,counter] =NLNR(X,F,MAXIT,counter,ABSER,RELER,ITEST)
while ITEST==1 %run loop as long as ITEST is 1
counter=counter+1; %use counter to keep track of iterations
dX=DFDX/(-F);
X=X+dX;
if abs(Y(1)-X(1))<ABSER %check convergence
ITEST=3;
end
if abs((Y(1)-X(1))/X(1))<RELER %check convergence
ITEST=3;
end
if counter>MAXIT %check divergence
ITEST=2;
end
Y(1)=X(1); %set Y to check diff in next loop
Y(2)=X(2);
end
end
jacobian. Check that you didn't do that, runclearand try againjacobian-matrixin this question... for the love of God please.jacobianrequires the Symbolic Math Toolbox