How to solve equations having product variables

3 次查看(过去 30 天)
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 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!