Skip to main content
2 of 7
added 52 characters in body
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Checking if all the variables are present in the defined function

I want to check if a user input the function with all the specified variables or not. For that I choose the replace variables with some values and check for if the result is a number or not via a doloop. I am thinking there might be more elegant way of doing it such as ReplaceList but it is not working the way I want it.

Lets assume

   u = z^2 Sin[π x] + z^4 Cos[π y] + I y^6 Cos[2 π y] + w;
   (*and user give variables as *)
   vas = {x, y, z, w};
   (* I need to check if all the variables are in the function *)

   Do[

   u = u /. vas[[i]] -> 1.1; 
   (* 1.1 is within where the function is going to get \
    evaluated *)

   If[i == 4, numc9 = NumericQ[u]; Print[numc9];]; 
   (* if numc9 False either there infinity or one of \
   the variables in the list is not present in the function or function      \
    has extra variable(s) *)

    Print[u];

    , {i, 4}]

Is there more elegant way doing it? This

Erdem
  • 889
  • 4
  • 11