Advertisement
JoelSjogren

8-ball

May 20th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.50 KB | None | 0 0
  1. u = [3; 2];
  2. r = 1;
  3. % Expecting x = [3; 0] or roughly x = [1.2; 2.7].
  4.  
  5. f = @(x) [x'*x+4*r*r-u'*u; x'*x-x'*u];
  6. fp = @(x) [2*x'; 2*x'-u'];
  7. x = [0; 1];
  8.  
  9. for i=1:10
  10.     x = x - fp(x)\f(x);
  11.     disp(x')
  12. end
  13.  
  14. #{
  15.  
  16. This is the output:
  17.  
  18. octave:3> main
  19.   -0.33333   5.00000
  20.    0.69504   3.45745
  21.    1.0777   2.8835
  22.    1.1509   2.7736
  23.    1.1538   2.7692
  24.    1.1538   2.7692
  25.    1.1538   2.7692
  26.    1.1538   2.7692
  27.    1.1538   2.7692
  28.    1.1538   2.7692
  29.  
  30. Good! Expected something like [1.2; 2.7].
  31.  
  32. }#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement