[Date Index]
[Thread Index]
[Author Index]
Re: Problems with Mathematica 8.0 Solve
*To*: mathgroup at smc.vnet.net
*Subject*: [mg114307] Re: Problems with Mathematica 8.0 Solve
*From*: leigh pascoe <leigh at evry.inserm.fr>
*Date*: Tue, 30 Nov 2010 04:06:29 -0500 (EST)
Le 27/11/2010 09:37, Daniel Lichtblau a =C3=A9crit :
> ----- Original Message -----
>> From: "leigh pascoe"<leigh at evry.inserm.fr>
>> To: mathgroup at smc.vnet.net
>> Sent: Friday, November 26, 2010 4:32:06 AM
>> Subject: [mg114198] Problems with Mathematica 8.0 Solve
>> Dear Mathgroup,
>>
>> Like many of you I have recently installed Mathematica 8.0 and have
>> been
>> exploring its new features. I have encountered the following problem
>> using the Solve Function:
>>
>> Firstly in Mathematica 7.0
>>
>> I try to solve the following two simultaneous equations
>> In[35]
>> eq1 == (b + d + f)/x - (a + b)/(1 + x) - 2*(c + d + e)/(1 + 2*x + y) -
>> (f + g)/(x + y) ==== 0
>> eq2 == (e + g)/y - (c + d + e)/(1 + 2*x + y) - (f + g)/(x + y) ==== 0
>>
>> In[36}
>> Timing[sols == Solve[{eq1, eq2}, {x, y}];]
>> Out[36]
>> {52.437, Null}
>>
>> A bit slow but it gives me the result I want. I then Simplify the
>> solutions and evaluate them with a set of vectors of the constants
>> {a,b,c,d,e,f,g}.
>>
>> subs == {{a -> 45, b -> 79, c -> 4, d -> 11, e -> 8, f -> 0, g -> =
2},
>> {a -> 95, b -> 85, c -> 9, d -> 13, e -> 6, f -> 0, g -> 1},
>> {a -> 18, b -> 45, c -> 0, d -> 1, e -> 2, f -> 0, g -> 0}, {a ->=
50,
>> b -> 41, c -> 0, d -> 1, e -> 0, f -> 0, g -> 0},
>> {a -> 17, b -> 61, c -> 1, d -> 9, e -> 14, f -> 0, g -> 1}, {a -=
>
>> 68, b -> 60, c -> 10, d -> 7, e -> 3, f -> 2, g -> 0},
>> {a -> 42, b -> 90, c -> 5, d -> 29, e -> 49, f -> 6, g -> 17}, {a=
->
>> 140, b -> 108, c -> 23, d -> 32, e -> 19, f -> 16, g -> 8}}
>>
>> nsols == Simplify[RootReduce[sols /. subs]]
>>
>> N[%]
>>
>> giving me the answers I want
>>
>> {{{y -> -2.18473, x -> 2.02599}, {y -> -0.0457403, x -> -0.53058}, {=
y
>> ->
>> 2.72299, x -> 1.70867}}, {{y -> -1.05434, x -> 1.00657}, {y ->
>> -0.0244319, x -> -0.536953},
>> {y -> 0.83139, x -> 0.871734}}, {{y -> -2.66667, x -> 2.66667}, {y -=
>
>> -0.0183209, x -> -0.50458}, {y -> 12.1294, x -> 2.53236}}, {{y ->
>> -0.84,
>> x -> 0.84},
>> {y -> 0., x -> -0.503749}, {y -> 0., x -> 0.833749}}, {{y -> -4.833=
81,
>> x -> 4.69898}, {y -> -0.100097, x -> -0.530885}, {y -> 12.0561, x ->
>> 3.63746}}, {{y -> -1.05985,
>> x -> 0.917926}, {y -> -0.014617, x -> -0.542283}, {y -> 0.351798, x
>> -> 0.797433}}, {{y -> -4.52487, x -> 3.85637}, {y -> -0.240225, x ->
>> -0.548865}, {y -> 7.61935, x -> 2.24569}},
>> {{y -> -1.46526, x -> 1.07904}, {y -> -0.0612374, x -> -0.561339}, {=
y
>> ->
>> 0.684794, x -> 0.770645}}}
>>
>> In Mathematica 8.0 this process hangs at the Solve command. I was
>> forced
>> to abort the evaluation after more than an hour with no result. The
>> program seems to use only 25% of the available cpu (i.e. 1 of the 4
>> available in the quadcore) and never arrives at a result. I thought
>> that
>> equation solving was much improved in the new version, so what is
>> going on?
>>
>> Perhaps there is a much better way to get the results I want. I need
>> to
>> evaluate the solutions to the above equations for large numbers of
>> data
>> vectors. I would appreciate any suggestions. Thanks in advance.
>>
>> LP
> We are not exactly sure why this worked better in earlier versions (we kn=
ow where it gets into trouble in version 8). First are some suggestions fro=
m Adam Strzebonski, regarding your use of parametrized Solve.
>
> "[...] mention that
> for the (hopefully rare) cases when the new Solve method turns out
> to be slower than the old one we still have the old method available.
>
> In[3]:== Timing[sols == Solve[{eq1, eq2}, {x, y}, Method->"Legacy"];]
> Out[3]== {15.4497, Null}
>
> Another possibility
>
> parallelSolve[args__] :==
> ParallelTry[#[args]&, {Solve, Solve[##, Method -> "Legacy"]&}]
>
> In[10]:== AbsoluteTiming[sol == parallelSolve[{eq1, eq2}, {x, y}];]
> Out[10]== {30.6728358, Null}
>
> Adam"
>
> Let me point out some other issues. First is that you will not save signi=
ficant time if your goal is to get "nice" results. Specifically, you can so=
lve relatively fast once you plug in those numeric values.
>
> In[5]:== Timing[solns == Map[Solve[(exprs /. #) ==== 0]&, Take[subs, 4]];=
]
> Out[5]== {0.889, Null}
>
> But the reduction is relatively slow.
>
> In[6]:== Timing[RootReduce[solns];]
> Out[6]== {161.009, Null}
>
> Also in version 8 you can readily suppress the radical solutions and then=
it will RootReduce quote quickly.
>
> In[6]:== Timing[
> solns == Map[Solve[(exprs /. #) ==== 0, Cubics -> False]&,
> Take[subs, 4]];]
> Out[6]== {0.063, Null}
>
> In[9]:== Timing[RootReduce[solns];]
> Out[9]== {0.032, Null}
>
> If your end goal is the numeric solutions, I generally recommend NSolve.
>
> In[10]:== Timing[Map[NSolve[exprs /. #]&, subs]]
>
> Out[10]== {0.28, {{{y -> -2.18473, x -> 2.02599}, {y -> 2.72299,
> x -> 1.70867}, {y -> -0.0457403, x -> -0.53058}}, {{y -> -1.0543=
4,
> x -> 1.00657}, {y -> -0.0244319, x -> -0.536953}, {y -> 0.83139=
,
> x -> 0.871734}}, {{y -> 12.1294, x -> 2.53236}, {y -> -0.0183209=
,
> x -> -0.50458}}, {}, {{y -> 12.0561,
> x -> 3.63746}, {y -> -4.83381, x -> 4.69898}, {y -> -0.100097,
> x -> -0.530885}}, {{y -> -1.05985,
> x -> 0.917926}, {y -> -0.014617, x -> -0.542283}, {y -> 0.351798=
,
> x -> 0.797433}}, {{y -> -4.52487, x -> 3.85637}, {y -> 7.61935,
> x -> 2.24569}, {y -> -0.240225, x -> -0.548865}}, {{y -> -1.4652=
6,
> x -> 1.07904}, {y -> -0.0612374, x -> -0.561339}, {y -> 0.68479=
4,
> x -> 0.770645}}}}
>
> Daniel Lichtblau
> Wolfram Research
>
>
>
Dear Daniel,
Thanks for your most helpful suggestions. It is good to know that the
legacy option is available for "symbolic" solution of the equations when
needed.
When writing about the method I have used to analyse my data, I can
write equations relating the parameters to be estimated {x,y} and the
observed data {a,b..,g}. Obviously in that case one would like to have
simple symbolic solutions, x==f(a,b..)etc. However in the present case
that seems impossible, as the symbolic solutions take up several pages
and give little insight. In any case no editor would permit publication
of the formulas for want of space.
To get numerical values for the parameters in a particular experiment
it is easy to substitute the observed data into the formulas to estimate
the parameters, in Ma 7.0.
In Mathematica 8.0 the solution of the equations seems impossible
(without invoking the legacy method), despite the fact that they appear
relatively simple. However numerical results can be obtained as
suggested in your email in two ways:
1. By substituting the data values into the equations first and then
solving them. The command you suggested doesn't in fact solve the
equations, I presume because of a misplacement of parentheses viz
Timing[solns == Map[Solve[(exprs /. #) ==== 0, Cubics -> False] &,
Take[subs, 4]];]
However it prompted me to find the syntax that did
sols == N[Map[Solve[expr /. #, Cubics -> False] &, subs2]]
2. The solutions can also be found using Nsolve directly as you suggested
sols2 == Map[NSolve[expr /. #] &, subs2]
In summary it turns out to be more efficient to solve the equations
multiple times with specific coefficients than to solve them generally
and evaluate the particular solutions.
The above commands solve my immediate problem but not my curiousity.
Could anyone comment on the methods used by 7.0 and 8.0 to solve systems
of equations? Why is it easier to solve the equations with exact
numerical coefficients than with symbolic constants? Would it be easier
if the data values were limited to positive integers? Is Reduce a
preferred command in this situation? I can't get much assistance from
the Help files on these questions.
Thanks again
LP
Prev by Date:
**Re: Why are my 3D plots blue?**
Next by Date:
** basic pattern matching**
Previous by thread:
**Re: Problems with Mathematica 8.0 Solve**
Next by thread:
**How do I take every 3rd number from a text file?**
| |