-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewtonMutiD.m
More file actions
69 lines (68 loc) · 1.78 KB
/
Copy pathNewtonMutiD.m
File metadata and controls
69 lines (68 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%A simple program that demonstrates the
% application of the NewtonRaphson method
% for multi-dimensional problems.
%*******************************************
%Created by: Mohammad Tawfik
%Email: mohammad.tawfik@gmail.com
%
%Code associated with lecture notes titled:
%Fundamentals of Numerical Analysis
%Published on ResearchGate.net at:
%https://www.researchgate.net/publication/321850359_Fundamentals_of_Numerical_Analysis_Book_Draft
%With DOI: 10.13140/RG.2.2.25680.81925
%Lecture videos are published on the
%#AcademyOfKnowledge website
%http://AcademyOfKnowledge.org
%
%With the direct link:
% https://sites.google.com/academyofknowledge.org/theakweb/engineering-and-science/applied-numerical-analysis
%
%*******************************************
%Clearing the memory
clear all
close all
clc
%Initial guesses
x=0.5;
y=0.5;
%Problem parameters
Epsilon = 1e-3; %Tolerance
MaxIter =20; %Maximum number of iterations
%Initializing the counter and error
Counter=0;
Err=1000;
%The search loop
while true
Counter=Counter+1; %Incrementing the counter
%Evaluating the function
% and its derivative at the new solution
SQT=sqrt(1-(x-1)*(x-1) - (y-1)*(y-1));
F1=(1-x)/SQT;
F2=(1-y)/SQT;
%Evaluatingthe derivatives
F1x=-(x-1)*(x-1)/(SQT^3)-1/SQT;
F1y=-(x-1)*(y-1)/(SQT^3);
F2x=-(x-1)*(y-1)/(SQT^3);
F2y=-(y-1)*(y-1)/(SQT^3)-1/SQT;
%Filling The Jacobian Matrix
JJ=[F1x,F1y;F2x,F2y];
J1=inv(JJ);
%Solving for the change
DeltaX=-J1*[F1;F2];
%Evaluating the new values
x=x+DeltaX(1);
y=y+DeltaX(2);
%Evaluating the relative error
Err=DeltaX'*DeltaX;
%Checking for termination
if or(and(F1==0,F2==0),or(Err<Epsilon,Counter>MaxIter))
break
end
end
%Displaying the solution
Counter
Err
x
y
F1
F2