solving nonlinear equations in Octave

2020-04-18 09:38发布

问题:

I am new to Octave and would like to know how to solve nonlinear equation. 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

回答1:

Use fzero to get the solution closest to a given x0 (well, not necessarily closest, but the first one found):

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.

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


回答2:

fsolve is a good place to start.