实验21求方程根的函数 本文档将给出用 Mathcad计算方程根的方法 求方程x3-17×+32=0在区间(-2,-1)、(1,2)、(16,17)中的根 方法1:调用root(fx),x,a,b])函数直接计算 g(x):=x-17x-+32 root(g(x),x,-2,-1)=-1.32158root(g(x),x,1,2)=1.43378rot(g(x),X,16,17)=168878 方法2:首先设置猜测值 1x3:=17 oot(g(xD), Xl) 1.3215968 ot(g(x2)x2 M=143378414 oot(g(x3), X3) 16.88779713 方法3:调用 polyroots(v)函数计算,其中v为多项式的系数向量. -1.32158 x-17x-+32 clefts,x→ polyroots(v)=1.43378 17 -17 16.8878 方法4:调用Gⅳven. Find求解模块,调用之前首先设置猜测值 X:=-2 Given x-17x+32=0Find(x)=-1.32158 X:=1 Given x-17x-+32=0Find(x)=143378292 x:=17 Given x-17x+32=0Find(x)=16.88779712 roots(a, b,c):=if b>4.ac 4..c xl← X← eror("根为复数") otherwise roots(2, 2, 3)
v 32 0 -17 1 æ ç ç ç ç è ö ÷ ÷ ÷ ÷ ø := polyroots(v) -1.32158 1.43378 16.8878 æ ç ç è ö ÷ ÷ ø = 方法4: 调用Given...Find 求解模块, 调用之前首先设置猜测值 x := -2 Given x 3 17x 2 - + 32 = 0 Find(x) = -1.32158 x := 1 Given x 3 17x 2 - + 32 = 0 Find(x) = 1.43378292 x := 17 Given x 3 17x 2 - + 32 = 0 Find(x) = 16.88779712 roots(a , b , c) x1 -b b 2 + - 4× a× c 2× a ¬ x2 -b b 2 - - 4× a× c 2× a ¬ b 2 if ³ 4×a× c error( "根为复数") otherwise x1 x2 æ ç è ö ÷ ø := roots(2 , 5 , 3) -1 -1.5 æ ç è ö ÷ ø = roots(2 , 2 , 3) 0 0 æ ç è ö ÷ ø = 实验21 求方程根的函数 本文档将给出用Mathcad计算方程根的方法. 求方程 x 3 - 17x + 32 = 0 在区间 (-2, -1) 、(1, 2)、(16, 17) 中的根. 方法1: 调用root(f(x), x, [a, b])函数直接计算 g(x) x 3 17x 2 := - + 32 root(g(x) , x , -2 , -1) = -1.32158 root(g(x) , x , 1 , 2) = 1.43378 root(g(x) , x , 16 , 17) = 16.8878 方法2: 首先设置猜测值 x1 := -2 x2 := 1 x3 := 17 M root(g(x1) , x1) root(g(x2) , x2) root(g(x3) , x3) æ ç ç è ö ÷ ÷ ø := M -1.3215968 1.43378414 16.88779713 æ ç ç è ö ÷ ÷ ø = 方法3: 调用polyroots(v) 函数计算, 其中v为多项式的系数向量. x 3 17x 2 - + 32 coeffs, x 32 0 -17 1 æ ç ç ç ç è ö ÷ ÷ ÷ ÷ ø ® 1
roots(a,b, c):= break if a=0 A←b--4 2·a roots(4,8,3)=(-0.5-1.5) roots(2,1,3)→ roots(0,3,1)=■ 0t0,3,=■ This is invalid. If you are using conditional statements in a Mathcad program, make sure all cases are accounted for
roots(a , b , c) break if a = 0 D b 2 ¬ - 4× a× c x1 -b + D 2× a ¬ x2 -b - D 2× a ¬ ( x1 x2 ) := roots(4 , 8 , 3) = ( -0.5 -1.5 ) roots(2 , 1 , 3) -1 4 1 4 + ×i× 23 -1 4 1 4 - ×i× 23 æ ç è ö ÷ ø ® roots(0 , 3 , 1) = 2