[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] what's wrong in my poly code?
From: |
Colin Torney |
Subject: |
Re: [Help-gsl] what's wrong in my poly code? |
Date: |
Mon, 13 Nov 2006 10:04:46 +0000 |
On Fri, 2006-11-10 at 20:55 +0100, Marco Maggi wrote:
> If I run the following GNU Octave code:
>
> real_coeffs = [1 2 3 4 5];
> roots(real_coeffs)
>
> I get:
>
> ans =
>
> -1.2878 + 0.8579i
> -1.2878 - 0.8579i
> 0.28782 + 1.4161i
> 0.28782 - 1.4161i
>
> if I run the following GSL code:
>
> #include <gsl/gsl_poly.h>
> #include <stdio.h>
> #include <stdlib.h>
>
>
> int
> main (int argc, const char *const argv[])
> {
> gsl_poly_complex_workspace * w;
> double coeffs[5] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
> double result[10];
> int e;
> size_t i;
>
>
> w = gsl_poly_complex_workspace_alloc(5);
> e = gsl_poly_complex_solve(coeffs, 5, w, result);
> gsl_poly_complex_workspace_free(w);
>
> for (i=0; i<8; i+=2)
> {
> printf("%f %f\n", result[i], result[i+1]);
> }
> return 0;
> }
>
> I get:
>
> 0.137832 0.678154
> 0.137832 -0.678154
> -0.537832 0.358285
> -0.537832 -0.358285
>
> what am I doing wrong?
>
> TIA
>
> --
> Marco Maggi
>
> "They say jump!, you say how high?"
> Rage Against the Machine - "Bullet in the Head"
>
>
>
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
Marco
It's just in wrong order
octave:3> co=[5 4 3 2 1];
octave:4> roots(co)
ans =
0.13783 + 0.67815i
0.13783 - 0.67815i
-0.53783 + 0.35828i
-0.53783 - 0.35828i
Colin