第五节用 Mathematica 解方程 Solve[ f[x]= =0,x] DSolve [degn ,y[x],x] Mathematica 用于解方程的命令: ?1、 Solve[f[x]= =0,x] ?2、 Nsolve [f[x]==0,x] ?3、 Roots[f[x]==0,x] ?4、 Reduce[f[x]==0,x] ?5、 FindRoot [f[x]==0,{x,x0}] ?6、 FindRoot [f[x]==0,{x,x0,x1}] 例1解方程 SolveA 2ab+ 2ax+ 2bx- 3abx+ 2x 2- 3ax 2- 3bx 2+ abx 2- 3x 3+ ax 3+ bx 3+ x 4 0,xE 88 x? 1< ,8 x? 2< ,8 x? - a< ,8 x? - b<<03 323222 4333 222???????????xbx ax x abx ax xabx bx ax ab 0 3 3323222 43332 222????????????xbx ax xabx bx ax xabx bx ax ab解: Nsolve [f[x]==0,x ] ?对于 5次及 5次以上的方程已经没有公式解?Solve[ ] 只能给出以 Roots 表示的抽象解?这时改用 Nsolve [ ] 能求出近似值。例3求五次方程的根 03 25????xxx改用 Nsolve [ ]可以得到近似解 Solve@ x^5+ x^2- x+ 3 0,xD只能得出符号解 Roots [ ] ?Roots 的用法有所区别,其输出的结果是逻辑表达式。 Roots@ x^2+ 3x- 2 0,xD x== 1 2I - 3- 17M热 x== 1 2I - 3+ 17M结果是两个逻辑表达式的”或”.为了转化成 x→a的形式,可以用 ToRules 函数。:: x? 1 2I - 3- 17M> ,: x? 1 2I - 3+ 17M>> 8 ToRules@ %D< Reduce[ ] ?Reduce 函数给出方程的全部解。? Reduce 函数详细讨论了各种可能的情况,而 Solve 只考虑了 a≠0的一种情况。 Out[24]= x b b 2 4ac 2a , x b b 2 4ac 2a Solve ax 2 bx c 0, x Reduce ax 2 bx c 0,x a 0&& x b b 2 4ac 2a x b b 2 4ac 2a a 0&&b 0&&x c b c 0&&b 0&&a 切线法 FindRoot [ eqn ,{x,x0}] ?对于没有初等函数解的方程, Solve 可能解不出来,这时用 FindRoot 求函数的近似解。用 FindRoot [egn ,{x,x0}] 时Mathematica 是根据牛顿迭代法求根的近似值。因此初值 x0 要选择的与真值不太远。例6求解方程 xx? cos In[28]:= Solve Cos x x,x Solve ::tdep : The equations appear to involve the variables to be solved for in an essentially non algebraic way .More… In[28]:= Solve Cos x x,x In[29]:=FindRoot Cosx x, x,0 Out[29]= x ?注意,用以上的方法得到的解是形式解的集合,不能直接在以后的运算中使用,如果希望在计算中使用方程的根,可以将这些形式根的值存入一个表中,表中的元素就可以带入各种的表达式中去进行计算了。
第五节用mathematica解方程 来自淘豆网m.daumloan.com转载请标明出处.