RosettaCodeData/Task/Roots-of-a-function/Maxima/roots-of-a-function.maxima

55 lines
1.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

e: x^3 - 3*x^2 + 2*x$
/* Number of roots in a real interval, using Sturm sequences */
nroots(e, -10, 10);
3
solve(e, x);
[x=1, x=2, x=0]
/* 'solve sets the system variable 'multiplicities */
solve(x^4 - 2*x^3 + 2*x - 1, x);
[x=-1, x=1]
multiplicities;
[1, 3]
/* Rational approximation of roots using Sturm sequences and bisection */
realroots(e);
[x=1, x=2, x=0]
/* 'realroots also sets the system variable 'multiplicities */
multiplicities;
[1, 1, 1]
/* Numerical root using Brent's method (here with another equation) */
find_root(sin(t) - 1/2, t, 0, %pi/2);
0.5235987755983
fpprec: 60$
bf_find_root(sin(t) - 1/2, t, 0, %pi/2);
5.23598775598298873077107230546583814032861566562517636829158b-1
/* Numerical root using Newton's method */
load(newton1)$
newton(e, x, 1.1, 1e-6);
1.000000017531147
/* For polynomials, JenkinsTraub algorithm */
allroots(x^3 + x + 1);
[x=1.161541399997252*%i+0.34116390191401,
x=0.34116390191401-1.161541399997252*%i,
x=-0.68232780382802]
bfallroots(x^3 + x + 1);
[x=1.16154139999725193608791768724717407484314725802151429063617b0*%i + 3.41163901914009663684741869855524128445594290948999288901864b-1,
x=3.41163901914009663684741869855524128445594290948999288901864b-1 - 1.16154139999725193608791768724717407484314725802151429063617b0*%i,
x=-6.82327803828019327369483739711048256891188581897998577803729b-1]