reorganize file structure

This commit is contained in:
2010-04-17 12:00:00 -05:00
parent 0da2092d89
commit 5bacd30bad
515 changed files with 2257 additions and 37 deletions

61
strut/Newton.m Executable file
View File

@@ -0,0 +1,61 @@
function x=newton(Fs,FPs,P0,y,P,TOL);
% NEWTON-RAPHSON ALGORITHM 2.3
%
% To find a solution to f(x) = 0 given an
% initial approximation p0:
%
% y,P can be used for additional info if the function
% requires it.
%
% Initially written by Burden and Faires, revised by
% B.A. Broughton, 10/01/1999
%
% INPUT: initial approximation p0; tolerance TOL;
% maximum number of iterations NO.
%
% OUTPUT: approximate solution p or a message of failure
TRUE = 1;
FALSE = 0;
F = inline(Fs,'x','P','y');
FP = inline(FPs,'x','P');
NO=150;
OUP = 1;
F0 = F(P0,P,y);
% STEP 1
I = 1;
OK = TRUE;
% STEP 2
while I <= NO & OK == TRUE
% STEP 3
% compute P(I)
FP0 = FP(P0,P);
D = F0/FP0;
% STEP 6
P0 = P0 - D;
F0 = F(P0,P,y);
% STEP 4
if abs(D) < TOL
% procedure completed successfully
% fprintf(OUP,'\nApproximate solution = %.10e\n',P0);
% fprintf(OUP,'with F(P) = %.10e\n',F0);
% fprintf(OUP,'Number of iterations = %d\n',I);
% fprintf(OUP,'Tolerance = %.10e\n',TOL);
OK = FALSE;
% STEP 5
else
I = I+1;
end
end
if OK == TRUE
% STEP 7
% procedure completed unsuccessfully
fprintf(OUP,'\nIteration number %d',NO);
fprintf(OUP,' gave approximation %.10e\n',P0);
fprintf(OUP,'with F(P) = %.10e not within tolerance %.10e\n',F0,TOL);
end
x = P0;