求解方程(组)
1. 线性方程组,形如 AX=B +++++++>>> 用左除号 / , 即 X=A/B;
2. 符号方程,形如 f(x)=0 或者 f(x)=q(x) +++++++>>> 用 solve, 求解代数方程符号解;
Examples:
· solve('p*sin(x) = r') chooses 'x' as the unknown and returns
· [x,y] = solve('x^2 + x*y + y = 3','x^2 - 4*x + 3 = 0') returns
· S = solve('x^2*y^2 - 2*x - 1 = 0','x^2 - y^2 - 1 = 0') returns the solutions in a structure.
· [u,v] = solve('a*u^2 + v^2 = 0','u - v = 1') regards 'a' as a parameter and solves the two equations for u and v.
· S = solve('a*u^2 + v^2','u - v = 1','a,u') regards 'v' as a parameter, solves the two equations, and returns S.a and S.u.
· [a,u,v] = solve('a*u^2 + v^2','u - v = 1','a^2 - 5*a + 6') solves the three equations for a, u and v.
注:solve('x^3-1000*x+1');
输出的答案是这么一长串:ans = 1000/(3*(- 1/2 + (108^(1/2)*3999999973^(1/2)*i)/108)^(1/3)) + (- 1/2 + (108^(1/2)*3999999973^(1/2)*i)/108)^(1/3)
- (3^(1/2)*(1000/(3*(- 1/2 + (108^(1/2)*3999999973^(1/2)*i)/108)^(1/3)) - ((108^(1/2)*3999999973^(1/2)*i)/108 - 1/2)^(1/3)
如何将该答案缩短呢?
加这两个语句:
digits(6);
vpa(ans)
得到的答案为:
ans =
31.6223 - 9.09495*10^(-13)*i
- 6.82121*10^(-13)*i - 31.6233
1.59162*10^(-12)*i + 0.001
3. 一般非线性方程组 +++++++>>> fsolve( 数值解 )
Reference Website:
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/fsolve.html
4. 单变量非线性方程求解 ( 单变量函数求零点 ) +++++++>>>fzero
Reference Website:
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/fzero.html
5. 多项式非线性函数求根 +++++++>>>r=roots(p)
6. 微分方程数值解 +++++++>>> ode