forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newton3.m
36 lines (28 loc) · 797 Bytes
/
newton3.m
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
function newton3(x0,y0,n)
% newton3(x0,y0,n)
%
% Uses Newtons method to solve real system for z^3 = 1
%
% x0,y0 -- initial guess
% n -- # of iterations; n = 0 gives interactive version
%
clf;
colors = ['kbgrcmy'];
ncolors = size(colors,2);
axis([-1.5 1.5 -1.5 1.5]); axis manual; hold on;
solx = [1 -.5 -.5]; soly = [0 -.8666 .8666];
plot(solx,soly,'rx');
nn = n; if n <= 0 nn = 100; end
v = [x0;y0];
fprintf('\n n point\n\n')
for i=0:nn
plot(v(1),v(2),[colors(mod(i,ncolors)+1),'o'])
fprintf(1,'%3d ',i)
fprintf(1,'%5.4f ',v')
fprintf(1,'\n')
if n <= 0 disp('Press any key to continue. . .'), pause;end
x = v(1); y = v(2);
w = [x^3 - 3*x*y^2 - 1; 3*x^2*y - y^3];
A = [3*x^2 - 3*y^2, -6*x*y;6*x*y, 3*x^2 - 3*y^2];
v = v - A\w;
end