Anonymous user
Roots of a function: Difference between revisions
Added GNU Scientific Library version to C
(Added EchoLisp) |
(Added GNU Scientific Library version to C) |
||
Line 279:
=={{header|C}}==
=== Secant Method ===
<lang c>#include <math.h>
#include <stdio.h>
Line 311 ⟶ 313:
}
return xB;
}
int main(int argc, char *argv[])
Line 340 ⟶ 342:
return 0;
}</lang>
=== GNU Scientific Library ===
<lang C>#include <gsl/gsl_poly.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
/* 0 + 2x - 3x^2 + 1x^3 */
double p[] = {0, 2, -3, 1};
double z[6];
gsl_poly_complex_workspace *w = gsl_poly_complex_workspace_alloc(4);
gsl_poly_complex_solve(p, 4, w, z);
gsl_poly_complex_workspace_free(w);
for(int i = 0; i < 3; ++i)
printf("%.12f\n", z[2 * i]);
return 0;
}</lang>
One can also use the GNU Scientific Library to find roots of functions. Compile with <pre>gcc roots.c -lgsl -lcblas -o roots</pre>
=={{header|C++}}==
|