How to solve equations having product variables

조회 수: 3 (최근 30일)
Yunji Seol
Yunji Seol 2018년 3월 31일
답변: Manan Mishra 2018년 4월 3일
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?

답변 (1개)

Manan Mishra
Manan Mishra 2018년 4월 3일
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)

카테고리

Help CenterFile Exchange에서 비선형 연립방정식에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!