Beruflich Dokumente
Kultur Dokumente
%
% this routine solves a nonlinear system with the Newton-Raphson
% iterative method
%
% The following steps are followed:
%
% 1)Reading of the parameters of the solution:
%
% -max number of iterations: max_iter
% -maximum variation to define convergence criteria: epsilon
% -number of equations in the non-linear system: Nsys
%
% 2)Reading of the equations
%
% -Reading of the equations of the non-linear system
% -Reading of the initial condition vector
% -Verification of the input data in order to detect incorrect inputs
%
% 3)Iterative calculation (repeated until convergence):
% 3.1)Assemblage of the matrix of derivate functions
% 3.2)Calculate the new value of the variables (given by this
% iteration)
% 3.3)Compare the difference between the new and old values with the
% converging criteria (epsilon)
%
% 4)Presentation and store of the result values
%
%
%%
%%%%% 1 Reading of the parameters of the solution:
epsilon=0.0000000001;
nsys=2;
%%
%%%%% 2)Reading of the (nsys)equations
% F1 = @(x) x(1)^2+x(2)^2-40;
k1=200000
k2=5000000;
Fac=126000;
set=0.01;
F1 = @(x) (1+((k1+k2*(set-x(1))^2)/Fac))*x(1)-0.707*x(2)-set*((k1+k2*(set-
x(1))^2)/Fac);
%Equation 2: (F2)
% a=5;
% F2 = @(x) x(1)-a;
F2 = @(x) -0.707*x(1)+1.5*x(2);
F={F1,F2};
nls_aleatory_initial_values;
%The values could instead be inputed one by one like done bellow:
%x(1)=1
%x(2)=4
%x(3)=6
%(to be created)
%(to be created)
%%
%%%%% 3)Iterative calculations
nloop=0;
nconverg=0;
while nloop<maxiter
dFidxj=zeros(nsys,nsys);
for i=1:1:nsys
for j=1:1:nsys
nls_derivada;
end
end
%%
%%%%% Calculation of the vector with the values of each function
for i=1:1:nsys
j=F{i};
D(i,1)=j(x);
end
%%
%%%%% Calculation of the error
A=inv(dFidxj);
error=A*D;
dx=error';
%%
%%%%% Adding the error to the x to obtain the new iteration
x=x-dx;
%%
%%%%% Parameter to determine the end of the while loop
nloop=nloop+1;
nconverg=nconverg+1;
%%
%%%% Converging criteria (error < epsilon)
maxdx=max(abs(error));
if maxdx<epsilon
nloop=maxiter;
end
end
%%
%%%%% 4)Presentation and store of the result values
x
nconverg
%%% The values of the variables x(1), x(2),... x(nsys) can now be atributed
%%% to their respective destines