MathGroup Archive 2012

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

Search the Archive

Re: recursively solve equation and save the values only

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125809] Re: recursively solve equation and save the values only
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Tue, 3 Apr 2012 04:50:02 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201204020827.EAA04300@smc.vnet.net>

f = 5.68672 T + 6.46776 T^3;

Recommend that you use Range rather than Table to generate values for t

t = Range[0.2, 3, 0.2];

Use ToRules with Reduce

sols = T /. Table[ToRules[Reduce[f == t[[i]], T, Reals]], {i, Length[t]}]

{0.0351204, 0.06995, 0.104221, 0.137709, 0.170237, 0.201687, 0.231988, \
0.26111, 0.289058, 0.315857, 0.34155, 0.366188, 0.389828, 0.412529, 0.434347}

With Solve

sols == (T /. Table[Solve[f == t[[i]], T, Reals][[1]], {i, Length[t]}])

True

Without Table

sols == (T /. ToRules[Reduce[f == #, T, Reals]] & /@ t)

True

sols == (T /. Solve[f == #, T, Reals][[1]] & /@ t)

True

Convert f to exact coefficients

f2 = Rationalize[f, 0];

Solve once with Reduce

g1[x_] = T /. (Reduce[f2 == x, T, Reals] // ToRules);

sols == g1 /@ t

True

Solve once with Solve

g2[x_] = T /. Solve[f2 == x, T, Reals][[1]];

sols == g2 /@ t

True


Bob Hanlon


On Mon, Apr 2, 2012 at 4:27 AM, wyn smjy <wsmjy2012 at gmail.com> wrote:
> Dear All,
>
> I am new to Mathematica. I am trying to recursively solve equation and
> saving the values into Table. Since I need the real solutions only so
> I use Reduce.
>
> The following is my code:
>
> f = 5.68672 T + 6.46776 T^3
>
> t = Table[i, {i, 0.2, 3, 0.2}]
>
> sols = Table[Reduce[f == t[[i]], T, Reals], {i, Length[t]}] {T ==
> 0.0351204, T == 0.06995, T == 0.104221, T == 0.137708, T == 0.170237,
> T == 0.201687, T == 0.231988, T == 0.26111, T == 0.289058, T ==
> 0.315857, T == 0.34155, T == 0.366188, T == 0.389828, T == 0.412529, T
> == 0.434347}
>
> The solution is OK as I compared it to other software as well. The
> only thing that matters me is how to remove the T== , i.e. I just need
> the solution and then to copy this into another table, say sols2 that
> contains
>
> sols2 = {0.0351204, 0.06995, 0.104221, T == 0.137708,.., 0.434347}
>
> I tried the following: sols2 = T/.sols but produce the following
> error:
>
> sols2 = ReplaceAll::reps: ... is neither a list of replacement rules
> nor a valid dispatch table, and so cannot be used for replacing. >>
>
> Does anyone know how to remove the T==?
>
> Thank you,
>
> Wayan
>



  • Prev by Date: Re: How do I stop Mathematica changing the format of fractions in Input cells?
  • Next by Date: Pattern Syntax for Alternate Heads with Default Value
  • Previous by thread: Re:recursively solve equation and save the values only
  • Next by thread: Re: recursively solve equation and save the values only