with text_io,integer_io; use text_io,integer_io; with Standard_Floating_Numbers; use Standard_Floating_Numbers; with Standard_Floating_Numbers_io; use Standard_Floating_Numbers_io; with Standard_Complex_Numbers; use Standard_Complex_Numbers; with Standard_Complex_Numbers_io; use Standard_Complex_Numbers_io; with Standard_Complex_Vectors; use Standard_Complex_Vectors; with Standard_Random_Vectors; use Standard_Random_Vectors; with Durand_Kerner; procedure ts_durker is -- DESCRIPTION : -- Test on the solver for polynomial equations in one variable. procedure Read ( cv : in out Vector ) is begin for i in cv'range loop put(' '); put(i,1); put(" : "); get(cv(i)); end loop; end Read; procedure Write ( step : in natural; z,res : in Vector ) is begin put("Output after step "); put(step,1); put_line(" :"); put_line ("------------------------------------------------------------------------"); put_line ("| APPROXIMATED ROOTS | RESIDUALS |"); put_line ("------------------------------------------------------------------------"); for i in z'range loop put("| "); put(z(i)); put(" | "); put(AbsVal(res(i))); put(" |"); new_line; end loop; put_line ("------------------------------------------------------------------------"); end Write; procedure dk is new Durand_Kerner(Write); procedure Main is n,nb : natural; begin put("Give the degree of p(x) : "); get(n); declare p : Vector(0..n); z,res : Vector(1..n); max : natural; eps : double_float; begin put_line("p(x) = a_0 + a_1*x + a_2*x^2 + ... + a_n*x^n"); put("Give "); put(n+1,1); put_line(" complex coefficients of p(x) :"); Read(p); z := Random_Vector(n); -- first approximation is random vector res := z; put("Give the maximum number of steps : "); get(max); put("Give the required accuracy : "); get(eps); dk(p,z,res,max,eps,nb); end; end Main; begin Main; end ts_durker;