Roots of a function: Difference between revisions
Content added Content deleted
(Added EchoLisp) |
(Added GNU Scientific Library version to C) |
||
Line 279: | Line 279: | ||
=={{header|C}}== |
=={{header|C}}== |
||
Step & check until close, then use Secant method. |
|||
=== Secant Method === |
|||
<lang c>#include <math.h> |
<lang c>#include <math.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 311: | Line 313: | ||
} |
} |
||
return xB; |
return xB; |
||
} |
|||
} |
|||
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
||
Line 340: | Line 342: | ||
return 0; |
return 0; |
||
}</lang> |
}</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++}}== |
=={{header|C++}}== |