# Numerically solving a system of three nonlinear equations by predefining functions [closed]

I have three functions of three variables, f1(x,y,z),f2(x,y,z), and f3(x,y,z), and I'm trying to solve them using Nsolve. Since in the original format, they are pretty long expressions, I first want to define them as f1,f2,f3 and then plug them into Nsolve. In a minimal reproducible example, I do the following:

f1[_x, _y, _z] = x^2 + y + 4 + 5*z
f2[_x, _y, _z] = x*y + y^2 + z + 4
f3[_x, _y, _z] = x*y*z

NSolve[f1 == 0, f2 == 0, f3 == 0, {x, y, z}]


But when I execute this, I get the same thing as an output:

NSolve[f1 == 0, f2 == 0, f3 == 0, {x, y, z}]


What am I missing?

## closed as off-topic by zhk, Bob Hanlon, J. M. will be back soon♦Sep 1 '17 at 15:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – zhk, Bob Hanlon, J. M. will be back soon
If this question can be reworded to fit the rules in the help center, please edit the question.

• @zhk Thanks, I fixed it, but the result remains the same. – sodiumnitrate Sep 1 '17 at 14:48

1. For a system you have to pass the argument as a list NSolve[{},{}].
2. When defining a function, each argument should be followed by an underscore, i.e., F[x_] not F[_x].

Thus

f1[x_, y_, z_] = x^2 + y + 4 + 5*z
f2[x_, y_, z_] = x*y + y^2 + z + 4
f3[x_, y_, z_] = x*y*z

NSolve[{f1[x, y, z] == 0, f2[x, y, z] == 0, f3[x, y, z] == 0}, {x, y, z}]


Only for real roots,

NSolve[{f1[x, y, z] == 0, f2[x, y, z] == 0, f3[x, y, z] == 0}, {x, y, z}, Reals]


{{x -> 4., y -> 0., z -> -4.}, {x -> -4., y -> 0., z -> -4.}}

• Thanks. Now it's just giving me an empty set, {}. To make sure I didn't make up a set of equations with no solution, I switched to a more trivial example, f1=x+y+z, f2=x, f3=y, which should give all zeros, but it still gives {}. – sodiumnitrate Sep 1 '17 at 14:53
• Ok, I missed the [x,y,z]s, so it works now. Thanks! – sodiumnitrate Sep 1 '17 at 14:54
• @sodi, if you think about it: you defined the f's with the brackets around; why would you omit them when you feed them to NSolve[]? – J. M. will be back soon Sep 1 '17 at 15:23