Post Reply 
What is wrong with my code?
01-23-2021, 02:30 PM
Post: #7
RE: What is wrong with my code?
(01-23-2021 01:25 AM)Spybot Wrote:  Using C.Ret's code and I'm getting this as a result: √((c-a)^2+(d-b)^2)

Hi, Spybot

It seems whatever entered into a,b,c,d does not stick.

I did a calculator reset before copy/paste your original code.
Except for the fact that it gives the "ungainly" convergent, everything else seems OK.

(01-21-2021 08:27 PM)C.Ret Wrote:  Since the variable r is most symbolic than a number, I don't initalize it to a real value,
nor I store any real value in it making the EXACT function "ungainly".

This may not be the reason for getting the "ungainly" convergent.

r := exact(√((c-a)^2+(d-b)^2));

In HOME mode, above is *not* the same as

r := √((c-a)^2+(d-b)^2);
r := exact(r);

HOME> r := sqrt(8)       // 2.82842712475
HOME> exact(r)            // 665857/235416

Storing √8 into r also turned it non-exact.
exact(r) does not turn float to exact, only a good convergent.

Combining 2 assignments into 1, we *mostly* avoided the non-exact path.
But, this assumed all inputs are integers.

Example, (a,b) = (1.,2.) , (c,d) = (3.,4.4):

r := exact(√((c-a)^2+(d-b)^2));                    // r = 2971372/951113

The more correct way is to rationalize the inputs.

r := simplify(√(exact(c-a)^2+exact(d-b)^2)); // r = 2*√61/5
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
What is wrong with my code? - Spybot - 01-20-2021, 09:05 PM
RE: What is wrong with my code? - rawi - 01-21-2021, 05:13 AM
RE: What is wrong with my code? - C.Ret - 01-21-2021, 08:27 PM
RE: What is wrong with my code? - Spybot - 01-23-2021, 01:25 AM
RE: What is wrong with my code? - Albert Chan - 01-23-2021 02:30 PM
RE: What is wrong with my code? - C.Ret - 01-23-2021, 07:56 PM
RE: What is wrong with my code? - Han - 01-24-2021, 03:31 AM
RE: What is wrong with my code? - Spybot - 01-24-2021, 03:40 PM



User(s) browsing this thread: 5 Guest(s)