Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9249 > unrolled thread
| Started by | Mike Sheppard <mikesheppard42@gmail.com> |
|---|---|
| First post | 2012-03-28 09:58 +0000 |
| Last post | 2012-03-29 08:07 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Using Table and ignoring all errors and warnings? Mike Sheppard <mikesheppard42@gmail.com> - 2012-03-28 09:58 +0000
Re: Using Table and ignoring all errors and warnings? A Retey <awnl@gmx-topmail.de> - 2012-03-29 07:56 +0000
Re: Using Table and ignoring all errors and warnings? Murta <rodrigomurtax@gmail.com> - 2012-03-29 08:07 +0000
| From | Mike Sheppard <mikesheppard42@gmail.com> |
|---|---|
| Date | 2012-03-28 09:58 +0000 |
| Subject | Using Table and ignoring all errors and warnings? |
| Message-ID | <jkunci$aqk$1@smc.vnet.net> |
I would like to use Table function, but have it ignore any errors or warnings and skip that value if one is produced.
Illustrative Example:
Table[1/i, {i, -3, 2}]
Power::infy: Infinite expression 1/0 encountered. >>
{-(1/3), -(1/2), -1, ComplexInfinity, 1, 1/2}
I would like the output to just be
{-(1/3), -(1/2), -1, 1, 1/2}
with no errors/warnings given as messages and the index that would produce a message to just be ignored. It's not just specific to 1/0 error, but any type of error or warning I want it to ignore it and skip to the next value; with the final output being a list of valid answers according to expr.
Is there a way to do that? Thanks!
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-03-29 07:56 +0000 |
| Message-ID | <jl14jf$l60$1@smc.vnet.net> |
| In reply to | #9249 |
Hi,
> I would like to use Table function, but have it ignore any errors or
> warnings and skip that value if one is produced.
>
> Illustrative Example:
>
> Table[1/i, {i, -3, 2}] Power::infy: Infinite expression 1/0
> encountered.>> {-(1/3), -(1/2), -1, ComplexInfinity, 1, 1/2}
>
> I would like the output to just be
>
> {-(1/3), -(1/2), -1, 1, 1/2}
>
> with no errors/warnings given as messages and the index that would
> produce a message to just be ignored. It's not just specific to 1/0
> error, but any type of error or warning I want it to ignore it and
> skip to the next value; with the final output being a list of valid
> answers according to expr.
>
> Is there a way to do that? Thanks!
There might be plenty, especially because your specification isn't that
precise :-)
Here is one version which works for your example:
Quiet[Table[Check[1/i, Unevaluated[Sequence[]]], {i, -3, 2}]]
hth,
albert
[toc] | [prev] | [next] | [standalone]
| From | Murta <rodrigomurtax@gmail.com> |
|---|---|
| Date | 2012-03-29 08:07 +0000 |
| Message-ID | <jl157m$leu$1@smc.vnet.net> |
| In reply to | #9249 |
On Mar 28, 6:58 am, Mike Sheppard <mikesheppar...@gmail.com> wrote:
> I would like to use Table function, but have it ignore any errors or warnings and skip that value if one is produced.
>
> Illustrative Example:
>
> Table[1/i, {i, -3, 2}]
> Power::infy: Infinite expression 1/0 encountered. >>
> {-(1/3), -(1/2), -1, ComplexInfinity, 1, 1/2}
>
> I would like the output to just be
>
> {-(1/3), -(1/2), -1, 1, 1/2}
>
> with no errors/warnings given as messages and the index that would produce a message to just be ignored. It's not just specific to 1/0 error, but any type of error or warning I want it to ignore it and skip to the next value; with the final output being a list of valid answers according to expr.
>
> Is there a way to do that? Thanks!
Hi Mike
There is one sugestion:
Table[1/i, {i, -3, 2}] // Quiet // DeleteCases[#, ComplexInfinity] &
Quiet removes the error msg
DeleteCases remove the unwanted complex
Best Regards
Murta
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web