-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroyden.m
More file actions
35 lines (28 loc) · 734 Bytes
/
broyden.m
File metadata and controls
35 lines (28 loc) · 734 Bytes
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
% Broyden's Method for finding solutions to nonlinear systems of equations
% currently used for the system:
% F(x,y) = [x^2 + y - 11;
% x + y^2 - 7]
% Jacobian is given below too
% given with initial guess [-0.164, 1]
clear
clc
F = @(x,y) [x^2 + y - 11; x + y^2 - 7];
J = @(x,y) [2*x, 1; 1, 2*y];
x0 = [-0.164;1]; % initial guess
N = 3000;
tol = 1e-7;
A0 = inv(J(x0(1),x0(2)));
k = 1;
while k < N
x = x0 - A0*F(x0(1),x0(2))
err = max([abs(x(1)-x0(1)), abs(x(2)-x0(2))])
if err <= tol
break;
end
s = x - x0;
y = F(x(1),x(2)) - F(x0(1),x0(2));
A = A0 + (s - A0*y)*(transpose(s))*A0/(transpose(s)*A0*y);
x0 = x;
A0 = A;
k = k + 1
end