0
$\begingroup$

I would like to perform the FindRoot command over the function func. Suppose:

func = Function[{x,y,z},{x+y+z,3x-y-0.5z}]

I would like to solve func==0 over the variables y, z over a grid of inputs x. Since my actual func is more complicated, I have to resort to using FindRoot rather than Solve.

One way to do this is to execute:

FindRoot[func[x0,y,z], {{y, y0}, {z, z0}}]

where x0 is a numeric input.

However, since my actual y, z consist of a large (and non-constant) number of variables, I wish to execute the following command:

FindRoot[func[x0, variables], {startingvariables}]

This however does not seem to work as either,

  • all variables have to be specified manually, or
  • the function has to be redefined

Is there a way out?

$\endgroup$
  • $\begingroup$ Please provide a working example, as FindRoot[func[x0,y,z],{{y,y0},{z,z0}] cannot work (you have one equation func[x0,y,z] == 0, but two unknowns, y and z). $\endgroup$ – LLlAMnYP Mar 17 '15 at 13:58
  • $\begingroup$ sorry for that! The system has 3 variables and 2 equations. I set one variable as fixed, so that remain 2 eqs + 2 unknowns $\endgroup$ – Breugem Mar 17 '15 at 14:46
1
$\begingroup$

As pointed out in the comments by @LLIAMnYP, FindRoot cannot solve one equation for two unknowns.

You may be able to use FindInstance

func = Plus;

n = 4; (* number of variables *)

var = Array[x, n];

x[1] = 5; (* fixed variable *)

ns = 4; (* number of solutions *)

For Integers

solnI = FindInstance[
  func @@ var == 0, Rest[var], Integers, ns]

{{x[2] -> -168, x[3] -> 39, x[4] -> 124}, {x[2] -> 66, x[3] -> -17,
x[4] -> -54}, {x[2] -> 134, x[3] -> -43, x[4] -> -96}, {x[2] -> 199,
x[3] -> -43, x[4] -> -161}}

Domain can be changed to Reals or Complexes (default). Inequalities can be used to constrain the domain.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.