简体   繁体   English

在八度中求解非线性方程

[英]solving nonlinear equations in Octave

I am new to Octave and would like to know how to solve nonlinear equation. 我是Octave的新手,想知道如何求解非线性方程。 Here is an example equation 这是一个示例方程式

x^4-16x^3+61x^2-22x-12=0

Update: 更新:

w+x+y+1=3

2w+3x+4y+5=10

w-x+y-1=4

thanks 谢谢

Use fzero to get the solution closest to a given x0 (well, not necessarily closest, but the first one found): 使用fzero获取最接近给定x0 (嗯,不一定最接近,但找到的第一个解):

This should work: 这应该工作:

x0 = 0;
f = @(x) x^4 - 16*x^3 + 61*x^2 - 22*x - 12;
fzero(f,x0);
ans =  0.76393

Also, you should check out roots , to get all the solutions of a polynomial. 另外,您应该检出roots ,以获取多项式的所有解。

x = [1 -16 61 -22 -12];  % The coefficients of your polynomial
y = roots(x)
y = 
   10.29150
    5.23607
    0.76393
   -0.29150

Ok, so I'll answer the second question anyway: 好吧,所以我还是要回答第二个问题:

x = [1 1 1; 2 3 4; 1 -1 1]; % Coefficients of w, x and y
y = [2; 5; 5];              % [3-1; 10-5; 4+1]

b = x\y
b =
   2.2500
  -1.5000
   1.2500

fsolve是一个不错的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM