# 2.3 Solving Equations # Art Belmonte, Summer 1996 # These are the shaded gray examples which appear in Section 2.3. > restart; x^2 + 2*x - 1 = 0; > sol:=solve(", x); 2 x + 2 x - 1 = 0 1/2 1/2 sol := 2 - 1, -1 - 2 > sol[1]; sol[2]; 1/2 2 - 1 1/2 -1 - 2 > f:=x^2 + 2*x - 1; 2 f := x + 2 x - 1 > solve(f=0, x); 1/2 1/2 2 - 1, -1 - 2 > eq:=x^2 + 2*x - 1 = 0; 2 eq := x + 2 x - 1 = 0 > solve(eq, x); 1/2 1/2 2 - 1, -1 - 2 > eq1:=3*x + 2*y = 1; eq2:=x + 2*y = 3; eq1 := 3 x + 2 y = 1 eq2 := x + 2 y = 3 > solve({eq1, eq2}, {x, y}); {y = 2, x = -1} > assign("); x, y; -1, 2 > unassign('x', 'y'); > eq:=x^3 - 2*x^2 + x - 3 = 0; > solve(eq, x); 3 2 eq := x - 2 x + x - 3 = 0 1/6 %2 + 2/3 %1 + 2/3, 1/2 - 1/12 %2 - 1/3 %1 + 2/3 + 1/2 I 3 (1/6 %2 - 2/3 %1), 1/2 - 1/12 %2 - 1/3 %1 + 2/3 - 1/2 I 3 (1/6 %2 - 2/3 %1) 1 %1 := ------------------- 1/2 1/3 (316 + 36 77 ) 1/2 1/3 %2 := (316 + 36 77 ) > eq:=x^3 - 2.0*x^2 + x - 3.0 = 0; 3 2 eq := x - 2.0 x + x - 3.0 = 0 > solve(eq, x); -.08727970515 - 1.171312111 I, -.08727970515 + 1.171312111 I, 2.174559410 > eq:=x^7 + 3*x^4 + 2*x - 1 = 0; 7 4 eq := x + 3 x + 2 x - 1 = 0 > solve(eq, x); 7 4 RootOf(_Z + 3 _Z + 2 _Z - 1) > fsolve(eq, x); .4414177090 > eq:=x^2 + 1/x - 1/x^2 = 0; 2 1 eq := x + 1/x - ---- = 0 2 x > fsolve(eq, x); -1.220744085 > plot(lhs(eq), x=-2..2, y=-20..20); > fsolve(eq, x, x=0..1); .7244919590 # Example of a parabola passing through three specified points. > p:=x->a*x^2 + b*x + c; 2 p := x -> a x + b x + c > eq1:=p(-1)=2; eq2:=p(1)=3/2; eq3:=p(4)=7; eq1 := a - b + c = 2 eq2 := a + b + c = 3/2 eq3 := 16 a + 4 b + c = 7 > sol:=solve({eq1, eq2, eq3}, {a, b, c}); sol := {c = 4/3, b = -1/4, a = 5/12} > evalf("); {c = 1.333333333, b = -.2500000000, a = .4166666667} > f:=subs(sol, p(x)); evalf("); plot(f, x=-2..5); 2 f := 5/12 x - 1/4 x + 4/3 2 .4166666667 x - .2500000000 x + 1.333333333 > with(plots); [animate, animate3d, changecoords, complexplot, complexplot3d, conformal, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, display3d, fieldplot, fieldplot3d, gradplot, gradplot3d, implicitplot, implicitplot3d, inequal, listcontplot, listcontplot3d, listdensityplot, listplot, listplot3d, loglogplot, logplot, matrixplot, odeplot, pareto, pointplot, pointplot3d, polarplot, polygonplot, polygonplot3d, polyhedraplot, replot, rootlocus, semilogplot, setoptions, setoptions3d, spacecurve, sparsematrixplot, sphereplot, surfdata, textplot, textplot3d, tubeplot] > eq:=x^2 + y^2 = 1; implicitplot(eq, x=-1..1, y=-1..1); 2 2 eq := x + y = 1 >