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
- :
- mathcad "acos" giving an imaginary angle, please h...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-29-2019
01:01 PM

07-29-2019
01:01 PM

Dear all,

I am using the direction cosines to find angle (or rather, the change in angle) along a curve at specific points.

But when the first part is a straight line, the change in angle should be zero (cos(theta) = 1.000) but mathcad is giving me cos(theta) = 1.00000000000000000000000000000000000000000000000001 or something and because of this, when I use the "acos" function, I am getting imaginary angles.

Currently I just added a 10^-20 to the denominator and the problem seemed to go away (maybe). But is there any way I can avoid this altogether ?

The calculation sheet is attached below. Please dont mind the extreme decimal values for the "y" variables. I am reading them from a curve and so they are like that .

Many thanks in advance !

Warm Regards,

Aravind.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

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

07-29-2019
01:41 PM

07-29-2019
01:41 PM

Here are four ways to deal with this round-off error:

1) use symbolic calculation, follow the costheta expression by a symbolic eval

2) use symbolic calc, right click the expression and chose "Optimize"

3) Round the result of costheta to just 15 decimals (guess this is the approach which directly addresses the problem)

4) Only use the real part of the angle

4 REPLIES 4

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

07-29-2019
01:27 PM

07-29-2019
01:27 PM

Re: mathcad "acos" giving an imaginary angle, please help ?

I understand that you use a formula to calculate cos(theta). When calculating numerically, you ALWAYS have to deal with uncertainty.

A 1 is a 1, but when it comes from e.g. 9 * (1/3)^, it might result in something slightly different from 1, due to internal representation of numbers.

To limit the result between -1 and 1, you could use:

cos_theta:=min( max( -1, expression), 1)

Where 'expression' is the formula you use to calculate cos(theta).

Success!

Luc

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

07-29-2019
01:41 PM

07-29-2019
01:41 PM

Here are four ways to deal with this round-off error:

1) use symbolic calculation, follow the costheta expression by a symbolic eval

2) use symbolic calc, right click the expression and chose "Optimize"

3) Round the result of costheta to just 15 decimals (guess this is the approach which directly addresses the problem)

4) Only use the real part of the angle

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

07-29-2019
01:57 PM

07-29-2019
01:57 PM

Re: mathcad "acos" giving an imaginary angle, please help ?

That would work just fine.

Thanks LucMeekes ! It's a shame I can't mark two answers as solutions

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

07-29-2019
02:04 PM

07-29-2019
02:04 PM

Re: mathcad "acos" giving an imaginary angle, please help ?

Hi Werner,

Thanks for the multiple solutions

Top Tags