Author 
Message 
Peter Pein science forum addict
Joined: 04 May 2005
Posts: 56

Posted: Wed Jul 19, 2006 9:39 am Post subject:
Re: mathematica: how to feed Solve output into Select?



markdemers15@hotmail.com schrieb:
Quote:  what documentation? i use their online mathematica documentation, and
they don't mention real or realQ. just mention ?positve and
?nonnegative.
Peter Pein wrote:
markdemers15@hotmail.com schrieb:
Thanks! It works.
Isn't it quite strange that mma uses
_?Positive and _?NonNegative
to query for positive numbers, but then mma uses
_Real
to query for reals. Why isn't it "_?Real" to maintain the same
pattern?
I'm sure you read the documentation carefully. So you should find the answer "_?RealQ" by yourself, shouldn't you?
Pē

Hello Mark,
my fault... Sometimes I forget having some packages in my init.m (in this case: DiscreteMath).
RealQ is in DiscreteMath`RSolve`.
Sorry,
Peter
P.S.: My remark regarding the documentation aimed mainly at the difference between "_Head" and "_?Function", which can easily be found in the docs (Ch. 2.3. of "The Mathematica Book"). 

Back to top 


double d science forum Guru
Joined: 03 May 2005
Posts: 640

Posted: Wed Jul 19, 2006 2:34 am Post subject:
Re: mathematica: how to feed Solve output into Select?



what documentation? i use their online mathematica documentation, and
they don't mention real or realQ. just mention ?positve and
?nonnegative.
Peter Pein wrote:
Quote:  markdemers15@hotmail.com schrieb:
Thanks! It works.
Isn't it quite strange that mma uses
_?Positive and _?NonNegative
to query for positive numbers, but then mma uses
_Real
to query for reals. Why isn't it "_?Real" to maintain the same
pattern?
I'm sure you read the documentation carefully. So you should find the answer "_?RealQ" by yourself, shouldn't you?
Pē 


Back to top 


Peter Pein science forum addict
Joined: 04 May 2005
Posts: 56

Posted: Tue Jul 18, 2006 5:13 pm Post subject:
Re: mathematica: how to feed Solve output into Select?



markdemers15@hotmail.com schrieb:
Quote:  Thanks! It works.
Isn't it quite strange that mma uses
_?Positive and _?NonNegative
to query for positive numbers, but then mma uses
_Real
to query for reals. Why isn't it "_?Real" to maintain the same
pattern?
I'm sure you read the documentation carefully. So you should find the answer "_?RealQ" by yourself, shouldn't you? 
Pē 

Back to top 


double d science forum Guru
Joined: 03 May 2005
Posts: 640

Posted: Tue Jul 18, 2006 4:55 pm Post subject:
Re: mathematica: how to feed Solve output into Select?



Thanks! It works.
Isn't it quite strange that mma uses
_?Positive and _?NonNegative
to query for positive numbers, but then mma uses
_Real
to query for reals. Why isn't it "_?Real" to maintain the same
pattern?
JeanMarc Gulliet wrote:
Quote:  magic math tricks wrote:
[...] how to
filter for only "Real" numbers (instead of Positive or Imaginary
numbers. In other words, I
want to do something like:
Cases[sol, {_ > _?Real}]
except that it doesn't seem to understand "Real".
Say we solve the following equation w/ two real and two complex roots
sol = Solve[(x^2 + 2)*(x^2  2) == 0]
returns
{{x > Sqrt[2]}, {x > (I)*Sqrt[2]}, {x > I*Sqrt[2]}, {x > Sqrt[2]}}
Now we get rid of the complex values using
Cases[N[x /. sol], _Real]
that returns
{1.4142135623730951, 1.4142135623730951}
HTH,
JeanMarc 


Back to top 


Dana DeLouis science forum beginner
Joined: 06 Mar 2006
Posts: 37

Posted: Tue Jul 18, 2006 1:17 pm Post subject:
Re: mathematica: how to feed Solve output into Select?



Here are some general ideas thrown out at random. Maybe there's something
here you can use:
You wanted the numbers in this format...
x /. Solve[x^4 + 4*x^3  7*x^2  22*x + 24 == 0]
{4, 3, 1, 2}
Suppose it returned a mixed group of numbers...
data = Union[Flatten[Table[{j, N[j], j*I}, {j, 2, 2}]]]
{2, 2., 1, 1., 0, I, I, 2*I, 2*I, 0., 1, 1., 2, 2.}
Cases[data, _Real  _Integer]
{2, 2., 1, 1., 0, 0., 1, 1., 2, 2.}
DeleteCases[data, _Complex]
{2, 2., 1, 1., 0, 0., 1, 1., 2, 2.}
Cases[data, _?Positive]
{1, 1., 2, 2.}
Cases[data, _?NonNegative]
{0, 0., 1, 1., 2, 2.}

HTH. :>)
Dana DeLouis
"magic math tricks" <markdemers15@hotmail.com> wrote in message
news:1153204082.976405.301880@m73g2000cwd.googlegroups.com...
Quote:  wow! Thanks Jean and Ted. This works! I am in heaven if you can tell
me how to
filter for only "Real" numbers (instead of Positive or Imaginary
numbers. In other words, I
want to do something like:
Cases[sol, {_ > _?Real}]
except that it doesn't seem to understand "Real".
Ted Hwa wrote:
In sci.math magic math tricks <markdemers15@hotmail.com> wrote:
: Thanks. Now you would make my life complete if you can tell me how to
: convert output such as { a1 > 3.3 , b8 > 4.8}
: into an array that looks like {3.3, 4.8}
: Any suggestiones?
{a1,b8} /. {a1 > 3.3, b8 > 4.8}
Ted



Back to top 


JeanMarc Gulliet science forum beginner
Joined: 28 May 2005
Posts: 38

Posted: Tue Jul 18, 2006 8:06 am Post subject:
Re: mathematica: how to feed Solve output into Select?



magic math tricks wrote:
Quote:  [...] how to
filter for only "Real" numbers (instead of Positive or Imaginary
numbers. In other words, I
want to do something like:
Cases[sol, {_ > _?Real}]
except that it doesn't seem to understand "Real".

Say we solve the following equation w/ two real and two complex roots
sol = Solve[(x^2 + 2)*(x^2  2) == 0]
returns
{{x > Sqrt[2]}, {x > (I)*Sqrt[2]}, {x > I*Sqrt[2]}, {x > Sqrt[2]}}
Now we get rid of the complex values using
Cases[N[x /. sol], _Real]
that returns
{1.4142135623730951, 1.4142135623730951}
HTH,
JeanMarc 

Back to top 


Peter Pein science forum addict
Joined: 04 May 2005
Posts: 56

Posted: Tue Jul 18, 2006 7:37 am Post subject:
Re: mathematica: how to feed Solve output into Select?



magic math tricks schrieb:
Quote:  wow! Thanks Jean and Ted. This works! I am in heaven if you can tell
me how to
filter for only "Real" numbers (instead of Positive or Imaginary
numbers. In other words, I
want to do something like:
Cases[sol, {_ > _?Real}]
except that it doesn't seem to understand "Real".
Ted Hwa wrote:
In sci.math magic math tricks <markdemers15@hotmail.com> wrote:
: Thanks. Now you would make my life complete if you can tell me how to
: convert output such as { a1 > 3.3 , b8 > 4.8}
: into an array that looks like {3.3, 4.8}
: Any suggestiones?
{a1,b8} /. {a1 > 3.3, b8 > 4.8}
Ted
as it seems to me you want a list of values (not rules) with some properties, 
IMHO these are the easiest ways:
Select[x /. Solve[(x^2 + 1)(x^2  1) == 0, x], Element[#, Reals] &]
x /. {ToRules[Reduce[(x^2 + 1)(x^2  1) == 0, x, Reals]]}
Peter 

Back to top 


double d science forum Guru
Joined: 03 May 2005
Posts: 640

Posted: Tue Jul 18, 2006 6:28 am Post subject:
Re: mathematica: how to feed Solve output into Select?



wow! Thanks Jean and Ted. This works! I am in heaven if you can tell
me how to
filter for only "Real" numbers (instead of Positive or Imaginary
numbers. In other words, I
want to do something like:
Cases[sol, {_ > _?Real}]
except that it doesn't seem to understand "Real".
Ted Hwa wrote:
Quote:  In sci.math magic math tricks <markdemers15@hotmail.com> wrote:
: Thanks. Now you would make my life complete if you can tell me how to
: convert output such as { a1 > 3.3 , b8 > 4.8}
: into an array that looks like {3.3, 4.8}
: Any suggestiones?
{a1,b8} /. {a1 > 3.3, b8 > 4.8}
Ted 


Back to top 


Ted Hwa science forum beginner
Joined: 03 May 2005
Posts: 43

Posted: Tue Jul 18, 2006 5:54 am Post subject:
Re: mathematica: how to feed Solve output into Select?



In sci.math magic math tricks <markdemers15@hotmail.com> wrote:
: Thanks. Now you would make my life complete if you can tell me how to
: convert output such as { a1 > 3.3 , b8 > 4.8}
: into an array that looks like {3.3, 4.8}
: Any suggestiones?
{a1,b8} /. {a1 > 3.3, b8 > 4.8}
Ted 

Back to top 


JeanMarc Gulliet science forum beginner
Joined: 28 May 2005
Posts: 38

Posted: Tue Jul 18, 2006 5:52 am Post subject:
Re: mathematica: how to feed Solve output into Select?



magic math tricks wrote:
Quote:  Thanks. Now you would make my life complete if you can tell me how to
convert output such as { a1 > 3.3 , b8 > 4.8}
into an array that looks like {3.3, 4.8}
Any suggestiones?
Dana wrote:
Would this idea work?
sol = Solve[x^4 + 4*x^3 
7*x^2  22*x + 24 == 0]
{{x > 4}, {x > 3},
{x > 1}, {x > 2}}
Cases[sol, {_ > _?Positive}]
{{x > 1}, {x > 2}}

HTH. :>)
Dana DeLouis
markdemers15@hotmail.com> wrote in message
news:1153175761.986651.321160@p79g2000cwp.googlegroups.com...
I have using Solve to solve coupled simultaneous equations for a vector
of values.
Solve comes up with a list of possible solutions.
Now, I wish to use Select to pick out the solutions that are in the
postive domain (e.g., every
element of the vector is nonnegative and real). But Select seems to
require regular "lists"
as input. How do I convert my Solve output into Select input?
Jacky
Hi Jacky, 
The Mathematica builtin function Solve returns a list of transformation
rules, each of one having the form "theVariable > aValue". Use the
replacement operator "/." to get the values only as in the following
example (example that draws on Dana's answer):
sol = Solve[x^4 + 4*x^3  7*x^2  22*x + 24 == 0]
so sol is equal to the list of transformation rules
{{x > 4}, {x > 3}, {x > 1}, {x > 2}}
Now, using the replacement operator
x /. sol
yields the following list of values
{4, 3, 1, 2}
as desired.
It might help to glance at section 1.4.2, "Values for Symbols", of _The
Mathematica Book Online_ at
http://documents.wolfram.com/mathematica/book/section1.4.2
Regards,
JeanMarc 

Back to top 


double d science forum Guru
Joined: 03 May 2005
Posts: 640

Posted: Tue Jul 18, 2006 4:59 am Post subject:
Re: mathematica: how to feed Solve output into Select?



Thanks. Now you would make my life complete if you can tell me how to
convert output such as { a1 > 3.3 , b8 > 4.8}
into an array that looks like {3.3, 4.8}
Any suggestiones?
Dana wrote:
Quote:  Would this idea work?
sol = Solve[x^4 + 4*x^3 
7*x^2  22*x + 24 == 0]
{{x > 4}, {x > 3},
{x > 1}, {x > 2}}
Cases[sol, {_ > _?Positive}]
{{x > 1}, {x > 2}}

HTH. :>)
Dana DeLouis
markdemers15@hotmail.com> wrote in message
news:1153175761.986651.321160@p79g2000cwp.googlegroups.com...
I have using Solve to solve coupled simultaneous equations for a vector
of values.
Solve comes up with a list of possible solutions.
Now, I wish to use Select to pick out the solutions that are in the
postive domain (e.g., every
element of the vector is nonnegative and real). But Select seems to
require regular "lists"
as input. How do I convert my Solve output into Select input?
Jacky



Back to top 


Dana DeLouis science forum beginner
Joined: 06 Mar 2006
Posts: 37

Posted: Tue Jul 18, 2006 2:21 am Post subject:
Re: mathematica: how to feed Solve output into Select?



Would this idea work?
sol = Solve[x^4 + 4*x^3 
7*x^2  22*x + 24 == 0]
{{x > 4}, {x > 3},
{x > 1}, {x > 2}}
Cases[sol, {_ > _?Positive}]
{{x > 1}, {x > 2}}

HTH. :>)
Dana DeLouis
<markdemers15@hotmail.com> wrote in message
news:1153175761.986651.321160@p79g2000cwp.googlegroups.com...
Quote:  I have using Solve to solve coupled simultaneous equations for a vector
of values.
Solve comes up with a list of possible solutions.
Now, I wish to use Select to pick out the solutions that are in the
postive domain (e.g., every
element of the vector is nonnegative and real). But Select seems to
require regular "lists"
as input. How do I convert my Solve output into Select input?
Jacky



Back to top 


double d science forum Guru
Joined: 03 May 2005
Posts: 640

Posted: Mon Jul 17, 2006 10:36 pm Post subject:
mathematica: how to feed Solve output into Select?



I have using Solve to solve coupled simultaneous equations for a vector
of values.
Solve comes up with a list of possible solutions.
Now, I wish to use Select to pick out the solutions that are in the
postive domain (e.g., every
element of the vector is nonnegative and real). But Select seems to
require regular "lists"
as input. How do I convert my Solve output into Select input?
Jacky 

Back to top 


Google


Back to top 



The time now is Thu Sep 20, 2018 7:29 am  All times are GMT

