Azzera filtri
Azzera filtri

How to solve equations having product variables

2 visualizzazioni (ultimi 30 giorni)
Yunji Seol
Yunji Seol il 31 Mar 2018
Risposto: Manan Mishra il 3 Apr 2018
I have 3 equations.
  • x+y+z=2
  • x+3y+4z=7
  • x-2y+3z+xy+yz+zy+xyz=6
When I search, many people use the "A\b" function, how should I write it in my case?
A = [ 1 1 1 0 0 0 0 0 ; 1 3 4 0 0 0 0 0; 1 -2 3 1 1 1 1 ];
b = [ 2; 7; 6];
I want to get value of x, y, z.
The above code is not correct, but I want to write it like that.
What function should be used to solve it?

Risposte (1)

Manan Mishra
Manan Mishra il 3 Apr 2018
You can use the function fsolve to solve a system of non-linear equations.
Please refer the following link to know more about this function:
You can also refer the examples in the above link for a better understanding of the function.
The following steps might help you:
1. Convert the equations to the form F(x) = 0.
2. Write a function that computes the left-hand side of these three equations.
3. Save this code as a file on your MATLAB path.
4. Solve the system of equations starting at the given point.
function f = eqn(x)
f(1) = x(1)+x(2)+x(3)-2;
f(2) = x(1)+3*x(2)+4*x(3)-7;
f(3) = x(1)-2*x(2)+3*x(3)+x(1)*x(2)+x(2)*x(3)+x(3)*x(1)+x(1)*x(2)*x(3)-6;
end
Save this function as a file and execute the following code.
func = @eqn;
x0 = [0,0,0];
x = fsolve(func,x0)

Categorie

Scopri di più su 비선형 연립방정식 in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!