Advertisement
Guest User

Untitled

a guest
Nov 10th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 2.20 KB | None | 0 0
  1. #=
  2.     Jakub Brodziński
  3.     229781@student.pwr.edu.pl
  4. =#
  5. using Polynomials;
  6. #=
  7.   Polynomial that we work with is "Wilkinson's polynomial" and we will be able to see why it's so special.
  8.  We have to import library to be able to call it's functions.
  9.   Variables:
  10.     input - array with polynomial's coefficients
  11.    input_2 - array with slightly modified polynomial's coefficients (we repeat Wilkinson's experiment)
  12.    k - array with precise polynomial's roots
  13.     P - polynomial created from a_n * x^n +... + a_1 * x^1 + a_0 presentation
  14.     p - polunomial created from (x-x0_n)(x-x0_n-1)...(x_x0_1) presentation
  15.     z_roots - array with roots calculated using library's function
  16. =#
  17.  
  18. input=Array{Float64,1}([1, -210.0, 20615.0,-1256850.0, 53327946.0,-1672280820.0, 40171771630.0, -756111184500.0, 11310276995381.0, -135585182899530.0,
  19. 1307535010540395.0, -10142299865511450.0, 63030812099294896.0, -311333643161390640.0, 1206647803780373360.0, -3599979517947607200.0,
  20.  8037811822645051776.0,-12870931245150988800.0, 13803759753640704000.0, -8752948036761600000.0, 2432902008176640000.0]);
  21.  
  22. input_2=Array{Float64,1}([1, Float64(-210.0-2.0^-23), 20615.0,-1256850.0, 53327946.0,-1672280820.0, 40171771630.0, -756111184500.0, 11310276995381.0, -135585182899530.0,
  23.   1307535010540395.0, -10142299865511450.0, 63030812099294896.0, -311333643161390640.0, 1206647803780373360.0, -3599979517947607200.0,
  24.    8037811822645051776.0,-12870931245150988800.0, 13803759753640704000.0, -8752948036761600000.0, 2432902008176640000.0]);
  25.  
  26. k=Array{Float64,1}(20);
  27. for i in 1:20
  28.  k[i]=i;
  29. end
  30.  
  31. P=Poly(flipdim(input,1));
  32. p=poly(k);
  33.  
  34. z_roots= roots(P);
  35.  
  36. #=
  37.  We present results via simple for loop.
  38. =#
  39.  
  40. for k in 1:20
  41.  println("k = ",k);
  42.  println("|P(z_k)|= ",abs(polyval(P,z_roots[k])),"\t|p(z_k)|= ",abs(polyval(p,z_roots[k])),"\t|z_k-k|= ",abs(z_roots[k]-k));
  43. end
  44.  
  45. #=
  46.  We repeat loop for little bit modified input (input_2)
  47. =#
  48.  
  49. P_2=Poly(flipdim(input_2,1));
  50. z_roots_2= roots(P_2);
  51.  
  52. #=
  53.  We present results via simple for loop.
  54. =#
  55.  
  56. for k in 1:20
  57.  println("k = ",k);
  58.  println("|P(z_k)|= ",abs(polyval(P_2,z_roots_2[k])),"\t|p(z_k)|= ",abs(polyval(p,z_roots_2[k])),"\t|z_k-k|= ",abs(z_roots_2[k]-k));
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement