Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16791
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail |
|---|---|
| From | Bob Hanlon <hanlonr357@gmail.com> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: checking the sign of all terms in a long expression |
| Date | Sun, 13 Apr 2014 09:25:30 +0000 (UTC) |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <lidl6a$cf$1@smc.vnet.net> (permalink) |
| References | <20140411061009.8DE2B6A30@smc.vnet.net> |
| Lines | 84 |
| Organization | Time-Warner Telecom |
| NNTP-Posting-Date | 13 Apr 2014 09:31:31 GMT |
| NNTP-Posting-Host | 50d75b2f.news.twtelecom.net |
| X-Trace | DXC=EGR9oLlhY6a@@WlPJcckEjC_A=>8kQj6m;[h;PUXBgbd?SWP;HjUf@fEFiONJ7[Gofo\00A0?m3Ik |
| X-Complaints-To | abuse@twtelecom.net |
| Xref | csiph.com comp.soft-sys.math.mathematica:16791 |
Show key headers only | View raw
Position works with general expressions not just lists. Replacing the head
Plus with the head List (List@@) is unnecessary.
toCheck = a + a b + a b c + a c - b + bc + d - e f;
Head[toCheck]
Plus
Flatten@Position[List @@ toCheck, Times[-1, __]]
{2, 8}
Flatten@Position[toCheck, Times[-1, __]]
{2, 8}
Bob Hanlon
On Sat, Apr 12, 2014 at 5:16 AM, Murray Eisenberg <murray@math.umass.edu>wrote:
> Are the symbols a, b, etc., just symbolic, as you seem to indicate, or
> might they be actual numeric values, too?
>
> If indeed the symbols a, b, etc. are just symbols and NOT numbers, then
> the following should help -- but note that Mathematica will automatically
> rearrange the terms of toCheck into its usual canonical form.
>
> toCheck = a + a b + a b c + a c - b + bc + d - e f
> (* a - b + a b + bc + a c + a b c + d - e f *)
>
> Flatten@Position[List@@toCheck, Times[-1,__]]
> (* {2, 8} *)
>
> If you insist on identifying the "negative" terms by their positions in
> the original expression, before it is evaluated, then you may want to treat
> it as a string, and the treatment will be trickier.
>
>
> On Apr 11, 2014, at 2:10 AM, dantimatter <google@dantimatter.com> wrote:
>
> >
> > hello all
> > is there to check the signs of all terms in a symbolic expression, like
> >
> > toCheck = a + a b + a b c + a c - b + bc + d ....
> >
> > in this case, with the assumption that the a, b, c etc are all positive,
> only one term is negative (b by itself) and the rest are positive. I have
> expressions like this that have a hundred or more terms and i'm worried i
> might not be catching all those that are of a different sign.
> >
> > thanks
> >
>
> Murray Eisenberg murray@math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower phone 240 246-7240 (H)
> University of Massachusetts
> 710 North Pleasant Street
> Amherst, MA 01003-9305
>
>
>
>
>
>
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar
Re: checking the sign of all terms in a long expression Bob Hanlon <hanlonr357@gmail.com> - 2014-04-13 09:25 +0000
csiph-web