cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Contributor

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

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 Smiley Happy.

 

Many thanks in advance !

 

Warm Regards,

Aravind.

1 ACCEPTED SOLUTION

Accepted Solutions

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

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

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

B1.png

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

B2.png

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

B.png

 

4 REPLIES 4

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

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

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

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

B1.png

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

B2.png

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

B.png

 

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 Smiley Happy

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

Hi Werner,

 

Thanks for the multiple solutions Smiley Happy