<Text-field layout="Heading 1" style="Heading 1">Chapter 6: Solving equations</Text-field>
<Text-field layout="Heading 2" style="Heading 2">Equations in a single variable</Text-field>
<Text-field layout="Heading 3" style="Heading 3">Symbolic</Text-field>restart;
<Text-field layout="Heading 4" style="Heading 4">Symbolic solutions</Text-field>s1:= solve( a*x^2 +b*x +c =0, x );
<Text-field layout="Heading 4" style="Heading 4">Exact solutions</Text-field>s2:= solve( x^2 -8*x +14 =0, x );
<Text-field layout="Heading 4" style="Heading 4"> Cubic equations</Text-field>Symbolic solutions:s3:= solve( a*x^3 +b*x^2 +c*x +d =0, x );Exact solutions:s4:= solve( x^3 +3*x^2 -2*x +7=0, x );evalf(s4); # Numerical valueNumerical solutions ( at least one coefficient is a floating point number):s4:= solve( x^3 +3*x^2 -2*x +7. =0, x );
<Text-field layout="Heading 4" style="Heading 4"> Solutions not in closed form</Text-field>s6:= solve( x^6 +3*x^5 +2 =0, x );1st root:s6;2nd root:s6;Numerical value of 2nd root:evalf(s6);Numerical value of all roots:evalf(s6);Numerical solutions:solve( x^6 +3.*x^5 +2. =0, x );
<Text-field layout="Heading 4" style="Heading 4">Transcendental equations</Text-field>s7:= solve( cos(x)-x/10 =0, x );Numerical values:evalf(s7);Check answer by plotting:plot( cos(x)-x/10, x=-15..15 );All seven solutions can be obtained numerically using fsolve (see next section).
<Text-field layout="Heading 3" style="Heading 3">Numerical</Text-field>
<Text-field layout="Heading 4" style="Heading 4"><Equation input-equation="cos*x-x = 0;" style="2D Comment">NiMvLCYqJiUkY29zRyIiIiUieEdGJ0YnRighIiIiIiE=</Equation></Text-field>There are roots near -9.6, -9.2, -4, -2, 1.5, 5, and 7 (see plot below):Plot:plot( cos(x)-x/10, x=-15..10 ); Solution in interval [-10, -9.5]:fsolve( cos(x)-x/10=0., x, -10..-9.5 );Solution in interval [-9.5, -8.8]:fsolve( cos(x)-x/10=0., x, -9.5..-8.8 );Solution in interval [-8.5, -8]:fsolve( cos(x)-x/10=0., x, -8.5..-8 ); # no solutionSolution near 1.5 :fsolve( cos(x)-x/10=0., x=1.5 );Result may be unexpected if the initial guess is near an extremum of y(x) (see "secant method" in Chapter 8):fsolve( cos(x)-x/10=0., x=0 );
<Text-field layout="Heading 4" style="Heading 4"><Equation input-equation="cos(x)+x/3 = 0;" style="2D Comment">NiMvLCYtJSRjb3NHNiMlInhHIiIiKiZGKEYpIiIkISIiRikiIiE=</Equation> </Text-field>There are 2 solutions near x=3 (see plot below):Plot:plot( cos(x)+x/3, x=2..4 ); This gives one of them:s1:= fsolve( cos(x)+x/3=0, x=3 );The other is obtained by using the option "avoid" :s2:= fsolve( cos(x)+x/3=0, x=.09, avoid={x=s1} );
<Text-field layout="Heading 2" style="Heading 2">Systems of equations</Text-field>restart;Linear eqs:E1:= J=2*K; E2:= K+J=27;solve( {E1,E2}, {J,K} );fsolve( {E1,E2}, {J,K} );restart;Non-linear eqs:E1:= x^2-y=5; E2:= x-y^2=-13;This misses 2 solutions:s:= solve( {E1,E2},{x,y} );evalf(s);This gives only 1 solutions:= fsolve( {E1,E2},{x,y} );Another trial:s:= fsolve( {E1,E2}, {x=2.9, y=4.1} );restart;This gives all 4 solutioons:E1:= x^2.-y=5.; E2:=x-y^2.=-13.;s:= solve( {E1,E2},{x,y} );There is a lesson here: be creative and try a few different ways to solve the problem and maybe one of them will work.