Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- zero not zero

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

In MathCAD, I used an expressions like:

if (cos(angle), expression 1, expression 2)

Meaning: if the cosine of the angle is not zero (TRUE), then evaluate expression 1, else expression 2.

or: if (1,2,3) yields 2

if (0,2,3) yields 3

I assumed that cos(PI/2) = 0.

BUT: it appears that 0 is not exactly 0. Even though I fill in n*(PI/2), and cos(angle) yields 0, the IF statement does not yield proper results.

Only if I round of cos(angle) at approx. 12-13 decimals, do I get proper results with the IF statement.

also, sign(cos(angle)) never yields 0, only 1 or -1. It should yield 0 at angle=PI/2.....

Did I miss something? Is there a better way then to "force" the results to 0 by rounding them off?

Any wizards here to help me out?

Thnks in advance,

tuduvu

if (cos(angle), expression 1, expression 2)

Meaning: if the cosine of the angle is not zero (TRUE), then evaluate expression 1, else expression 2.

or: if (1,2,3) yields 2

if (0,2,3) yields 3

I assumed that cos(PI/2) = 0.

BUT: it appears that 0 is not exactly 0. Even though I fill in n*(PI/2), and cos(angle) yields 0, the IF statement does not yield proper results.

Only if I round of cos(angle) at approx. 12-13 decimals, do I get proper results with the IF statement.

also, sign(cos(angle)) never yields 0, only 1 or -1. It should yield 0 at angle=PI/2.....

Did I miss something? Is there a better way then to "force" the results to 0 by rounding them off?

Any wizards here to help me out?

Thnks in advance,

tuduvu

Labels:

12 REPLIES 12

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

Eek! That's a nasty bug.

Richard

Richard

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

Yes, a nasty one.

It gets even worse (for me).

I have set up a complex calculation with a lot of gonimetric functions, and e.g. for n*PI/2 it creates a chaos-formula (extremely narrow and high spikes). So I need to filter out these arguments, and I round off the cos(angle), to force it to 0. E.g. at 14 decimals.

When n gets large, I need to set the accuracy to fewer decimals (n can get up to 10^6), e.g. to 12.

Also, I need to figure out the quadrant where, for a certain argument, the function is.

I use sign(cos(angle)), that yields only 1 and -1, never 0, as it should for the nagles mentioned.

I think I need to develop a kind of magnet function, meaning that all angle values are being left as they are, unless they are close to the problem-causing angles. Then they should snap to a better-evaluated constant, like (example 312/214).

Anyone knows an approximate for PI?

Funny: in Excel everything worked fine. It appears that one can be too accurate......

tuduvu

It gets even worse (for me).

I have set up a complex calculation with a lot of gonimetric functions, and e.g. for n*PI/2 it creates a chaos-formula (extremely narrow and high spikes). So I need to filter out these arguments, and I round off the cos(angle), to force it to 0. E.g. at 14 decimals.

When n gets large, I need to set the accuracy to fewer decimals (n can get up to 10^6), e.g. to 12.

Also, I need to figure out the quadrant where, for a certain argument, the function is.

I use sign(cos(angle)), that yields only 1 and -1, never 0, as it should for the nagles mentioned.

I think I need to develop a kind of magnet function, meaning that all angle values are being left as they are, unless they are close to the problem-causing angles. Then they should snap to a better-evaluated constant, like (example 312/214).

Anyone knows an approximate for PI?

Funny: in Excel everything worked fine. It appears that one can be too accurate......

tuduvu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

It still seems to be chopped. Maybe this will work:

As a rule of thumb, instead of writing if(x=0,1,2) one should write if(abs(x) is less than epsilon,1,2).

Robert

As a rule of thumb, instead of writing if(x=0,1,2) one should write if(abs(x) is less than epsilon,1,2).

Robert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

Would this function help?

Richard

Richard

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

Has anyone gotten extended-precision arithmetic to work with the symbolic processor? I'm trying to make a function that takes an extended-precision number and returns an extended-precision answer, but it doesn't seem to work. I'm attaching a worksheet that shows it working under some very special circustances for cos.

Also, I mentioned earlier that atan2 returns an answer from 0 to 2pi, actually it's -pi to pi and angle returns a value from 0 to 2pi.

Robert

Also, I mentioned earlier that atan2 returns an answer from 0 to 2pi, actually it's -pi to pi and angle returns a value from 0 to 2pi.

Robert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-05-2002
03:00 AM

11-05-2002
03:00 AM

zero not zero

OK, it helps if I attach the file.

Robert

Robert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-06-2002
03:00 AM

11-06-2002
03:00 AM

zero not zero

This is what I get (apparently the trick does not work in all cases):

Xavier

Xavier

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-06-2002
03:00 AM

11-06-2002
03:00 AM

zero not zero

arg(z) also returns an angle within [-pi, pi].

By the way, I've found in the past that the acos() function is also rather unreliable near zero.

Xavier

By the way, I've found in the past that the acos() function is also rather unreliable near zero.

Xavier

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-06-2002
03:00 AM

11-06-2002
03:00 AM

zero not zero

OK. After a night's sleep, here is what I came up with:

zero:= 0.0001 (or as small as needed)

cos.r(angle):= if(|cos(angle)| < zero, 0, cos(angle))

cos.r to be used instead of cos, when applicable (like sign / if statements)

Thanks to all of you. It was my first post in this forum, and I am happy to see the enthousiasm displayed here.

tuduvu

zero:= 0.0001 (or as small as needed)

cos.r(angle):= if(|cos(angle)| < zero, 0, cos(angle))

cos.r to be used instead of cos, when applicable (like sign / if statements)

Thanks to all of you. It was my first post in this forum, and I am happy to see the enthousiasm displayed here.

tuduvu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-06-2002
03:00 AM

11-06-2002
03:00 AM

zero not zero

Here's a function that forces cos(x) to be zero when x is odd-integer multiple of pi/2. It is very ugly looking, but I think it works. No guarantees though!

Richard

Richard