Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9382
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: recursively solve equation and save the values only |
| Date | 2012-04-03 08:52 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jlednh$h2o$1@smc.vnet.net> (permalink) |
On 4/2/12 at 4:27 AM, wsmjy2012@gmail.com (wyn smjy) wrote:
>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
It is generally a bad habit to use a single upper case letter as
a variable in Mathematica. There are too many instances where
this conflicts with built-in symbols. Avoiding this habit
ensures such conflicts cannot arise.
>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}
More efficient would be:
sols = Table[Reduce[f == i, t, Reals], {i, 0.2, 3, 0.2}];
>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:
This won't work since t == value isn't a replacement rule. Given
usage of Reduce the numeric values can be extracted using Cases.
That is:
In[17]:= Cases[sols, _?NumericQ, Infinity]
Out[17]= {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}
But do note, you could have obtained exactly the same result
using NSolve. For example,
In[18]:= sols =
Flatten@Table[t /. NSolve[f == i, t, Reals], {i, .2, 3, .2}]
Out[18]= {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}
I've used Flatten since NSolve returns a list rather than a number.
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: recursively solve equation and save the values only Bill Rowe <readnews@sbcglobal.net> - 2012-04-03 08:52 +0000
csiph-web