MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: extracting the information from Solve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27832] Re: extracting the information from Solve
  • From: "Mark Harder" <harderm at ucs.orst.edu>
  • Date: Mon, 19 Mar 2001 01:29:28 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Martin,
    To assign values from a list of replacement rules to their corresponding
symbols, all you need do is use Replace (or /.) To assign any one symbol :

In[16]:= a[1] /. equation;
Out[16]= {-0.56844};

or to assign the whole list:

varList = Flatten[{a[0], Array[a, 6], Array[b, 5]} ];
valList = Flatten[varList /. equation ]
Out[4]= {a[0], a[1], a[2], a[3], a[4], a[5], a[6], b[1], b[2], b[3], b[4],
b[5]}

In[17]:= Table[{varList[[i]], valList[[i]]}, {i, Length[varList ]} ] //
TableForm

Out[18]//TableForm=
\!\(\*
  TagBox[GridBox[{
        {\(a[0]\), \(-0.09583333333333338`\)},
        {\(a[1]\), \(-0.5684401076758503`\)},
        {\(a[2]\), "0.1625`"},
        {\(a[3]\), "0.175`"},
        {\(a[4]\), \(-0.10416666666666669`\)},
        {\(a[5]\), \(-0.10655989232414974`\)},
        {\(a[6]\), "0.037500000000000006`"},
        {\(b[1]\), \(-0.21598820239201746`\)},
        {\(b[2]\), "0.3680607966083865`"},
        {\(b[3]\), "1.8505975831611954`*^-17"},
        {\(b[4]\), \(-0.0793856620135736`\)},
        {\(b[5]\), "0.11598820239201736`"}
        },
      RowSpacings->1,
      ColumnSpacings->3,
      RowAlignments->Baseline,
      ColumnAlignments->{Left}],
    (TableForm[ #]&)]\)

, and so forth.

-mark harder
harderm at ucs.orst.edu


-----Original Message-----
From: Martin Richter <mr.fi at cbs.dk>
To: mathgroup at smc.vnet.net
Subject: [mg27832] [mg27784] extracting the information from Solve


>Hi,
>
>I really don't know why I'm so bad programming in Mathematica :-(  Here
goes
>my problem. I have 12 linear equation, 13 variables, and Mathematica (4.1)
>gives the following:
>
>
>f[t_] = a[0] + Sum[a[i]*Cos[2*Pi*i*t] + b[i]*Sin[2*Pi*i*t], {i, 1, 6}];
>seasonTab = {{0/12, -0.5}, {1/12, -.2}, {2/12, -0.5}, {3/12, -0.5}, {4/12,
>        0. - .25}, {5/12, 0.1}, {6/12, 0.5}, {7/12, 0.7}, {8/12,
>        1.1}, {9/12, -0.3}, {10/12, -0.7}, {11/12, -0.6}};
>equation =
>    Solve[{f[0/12] == seasonTab[[1, 2]], f[1/12] == seasonTab[[2, 2]],
>        f[2/12] == seasonTab[[3, 2]], f[3/12] == seasonTab[[4, 2]],
>        f[4/12] == seasonTab[[5, 2]], f[5/12] == seasonTab[[6, 2]],
>        f[6/12] == seasonTab[[7, 2]], f[7/12] == seasonTab[[8, 2]],
>        f[8/12] == seasonTab[[9, 2]], f[9/12] == seasonTab[[10, 2]],
>        f[10/12] == seasonTab[[11, 2]], f[11/12] == seasonTab[[12, 2]]}];
>equation
>
>
>\!\({{a[0] -> \(-0.09583333333333333`\), a[1] -> \(-0.5684401076758503`\),
>      a[2] -> 0.16249999999999998`, a[3] -> 0.17500000000000002`,
>      a[4] -> \(-0.10416666666666667`\), a[5] -> \(-0.10655989232414972`\),
>      a[6] -> 0.03750000000000004`, b[1] -> \(-0.2159882023920174`\),
>      b[3] -> 6.543001678297708`*^-17, b[5] -> 0.11598820239201749`,
>      b[2] -> 0.3680607966083864`, b[4] -> \(-0.07938566201357357`\)}}\)
>
>My problem is that a[i] and b[i] is only defines by a rule and not by the
>values, so evaluating f[1] doesn't put in the values of a[i] and b[i]. I
>want to assign the numbers to the a and b list so that
a[0]=-0.095833333,...
>
>Of course, you can do it manually. I thought that a simple loop would do
but
>the list is not sorted, b[3] is coming before b[2]. I have been looking in
>the Mathematica book, specially about Rule, Sort and equation but for no
>good.
>
>So, can you Sort or assign in a simple way
>
>FIA
>Martin
>
>ps. Is Mathematica written in C++ ?
>
>---------------------------------------
>Please remove PET to reply by email
>
>
>



  • Prev by Date: Re: NIntegrate problem
  • Next by Date: Re: NSolve problem
  • Previous by thread: Re: extracting the information from Solve
  • Next by thread: AW: Greek characters in exported *.eps