Because of some formulas with Conjugate in a notebook, I have to tell mathematica to change a lot of parameters to Real! I know that I can use Refine with Element or Assumptions:

Refine[k + x + g, Element[x | k | g, Reals]]


Refine[%, Assumptions -> {x, k, g} \[Element] Reals]

, But it's useful for a few parameters not a lot!

For Example I'd like to define:

Ki,j & i{1 to 20} , j{1 to 20}

in Reals. Is there any function to define it without telling mathematica one by one?


closed as off-topic by Yves Klett, m_goldberg, gpap, dr.blochwave, Dr. belisarius May 19 '15 at 12:36

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

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Yves Klett, m_goldberg, gpap, dr.blochwave, Dr. belisarius
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey May 11 '15 at 14:49
  • 6
    $\begingroup$ Start by not using parameters with subscripts. They look pretty, but they are a pain to deal with. Rename the variables: e.g. use bi instead of Subscript[b,i]. Another tip: don't use uppercase single letter variable names: they can conflict with built-in symbols. For instance, K is already an existing symbol (try and execute ?K). $\endgroup$ – MarcoB May 11 '15 at 15:01
  • 1
    $\begingroup$ You can specify a domain for some functions. There are Cases, Variables and other functions that might be useful in extracting the parameters from your code. -- As written currently, this question is a bit too broad. Can you provide a minimal working example, that would be typical of the problem that concerns you? $\endgroup$ – Michael E2 May 11 '15 at 16:29
  • $\begingroup$ For Example I'd like to define Ki,j & i{1 to 20} & j{1 to 20} in Reals. Is there any function to define it without telling mathematica one by one? $\endgroup$ – Maryam.D May 16 '15 at 7:07
  • $\begingroup$ Please add that information to the question and supply some examples to avoid unnecessary effort. General advice: avoid subscripts. They are a big source of confusion. $\endgroup$ – Yves Klett May 16 '15 at 7:35

I'm not sure what you mean by Ki,j but perhaps this

vars = ToExpression@
   Flatten@Table["K" <> ToString[i] <> "$" <> ToString[j], {i, 20}, {j, 20}];

or this

vars = Flatten@Table[k[i, j], {i, 20}, {j, 20}];

Then one can use it thus:

Assuming[vars ∈ Reals,
    Sqrt[vars ^ RandomInteger[4, Length[vars]]]
    ]] /. p_Power :> Simplify[p]
(* large expression with Sqrt[x^2] simplified to Abs[x] etc. *)

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