5
$\begingroup$

I am trying to solve a set of equations which are very ugly and have indexed variables. I have a vector of expressions

{c[0, 4, 0] + (3221 c[0, 4, 2])/11520 + (5956135 c[0, 4, 4])/
  37158912 + (280835610335 c[0, 4, 6])/1748974436352 + c[2, 0, 0] - (
  47 c[2, 0, 2])/2304 - (24863 c[2, 0, 4])/5308416 - (
  27473615 c[2, 0, 6])/12230590464, 
 23/48 c[0, 4, 2] + (23207 c[0, 4, 4])/55296 + (
  6316272121 c[0, 4, 6])/12145655808 + 23/48 c[2, 0, 2] + (
  5543 c[2, 0, 4])/55296 + (3892727 c[2, 0, 6])/84934656, 
 1/4 c[0, 4, 2] + (689 c[0, 4, 4])/1536 + (57501463 c[0, 4, 6])/
  77856768 + 1/4 c[2, 0, 2] + (433 c[2, 0, 4])/1536 + (
  1288613 c[2, 0, 6])/7077888, 
 23/96 c[0, 4, 4] + (1718215 c[0, 4, 6])/2875392 + 
  23/96 c[2, 0, 4] + (60835 c[2, 0, 6])/221184, 
 1/16 c[0, 4, 4] + (47825 c[0, 4, 6])/159744 + 1/16 c[2, 0, 4] + (
  2645 c[2, 0, 6])/12288, 23/256 c[0, 4, 6] + 23/256 c[2, 0, 6], 
 1/64 c[0, 4, 6] + 1/64 c[2, 0, 6]}

which I equate to the vector

{494/(6561 Sqrt[\[Pi]]), 31579/(51030 Sqrt[\[Pi]]), 33529/(
 17010 Sqrt[\[Pi]]), 5359/(1701 Sqrt[\[Pi]]), 508/(
 189 Sqrt[\[Pi]]), 368/(315 Sqrt[\[Pi]]), 64/(315 Sqrt[\[Pi]])}

and then use Solve to solve for the c[p,q,r]. The thing is that I would like to save these values, say in a table such that C[[p,q,r]] returns me the value c[p,q,r] which I obtained above. How can one do this? Note that the number of independent equations in the above are actually less than the number of unknowns so the system is under-constrained. I would like to set the excess number of variables to zero and then get the rest in terms of the ones set to 0 and store that so that I can access them easily.

How can one do this?

$\endgroup$

1 Answer 1

4
$\begingroup$

First, use Solve to get the solution:

sol = First@Solve[{c[0, 4, 0] + ...} == {494/(6561 Sqrt[π]), ...}];

Now iterate through the values and put them in another symbol. Instead of putting them in a table, I suggest using downvalues. And I will avoid capital C by using cc instead:

(Evaluate[cc @@ #1] = (#2 /. c[__] -> 0)) & @@@ sol

The solutions are now stored inside cc.

Definition[cc]
(* 
 cc[2, 0, 0] = 429/(4096 Sqrt[π])
 cc[2, 0, 2] = 47/(112 Sqrt[π])
 cc[2, 0, 4] = -(16/(9 Sqrt[π]))
 cc[2, 0, 6] = 4096/(315 Sqrt[π])
*)
$\endgroup$
5
  • $\begingroup$ Hi @Domen , thanks for the solution. It works as I would like it to. Can you explain what the Evaluate[cc@@#1]... bit is doing exactly? I have seen apply and map before but this is new. Thanks. $\endgroup$
    – QFTheorist
    Commented Feb 3 at 16:16
  • $\begingroup$ Sure! If you simply write cc@@c[2,0,0] = ... which is equivalent to Apply[cc, c[2, 0, 0]] = ..., Mathematica will complain that you are trying to assign some value to the Apply! This is because Set has the attribute HoldFirst. To overcome this, we use Evaluate such that cc@@c[2,0,0] is evaluated first to cc[2,0,0], and only then Set is called to set the value. $\endgroup$
    – Domen
    Commented Feb 3 at 17:34
  • $\begingroup$ Thanks. @Domen would it be possible to keep the values of the terms that I have set to 0 too? i.e. something like cc[a,b,c] = 0. $\endgroup$
    – QFTheorist
    Commented Feb 3 at 18:53
  • $\begingroup$ Only for those that were actually present or for any of them? In the second case, you can simply add cc[__] = 0. $\endgroup$
    – Domen
    Commented Feb 3 at 19:13
  • $\begingroup$ Thanks so much! Only those were present, yes. $\endgroup$
    – QFTheorist
    Commented Feb 3 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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