I feel like I'm over thinking this one..
I'm making a calculus program that does newtons method for you.
You input the function, it's derivative, your starting value and the number of decimals you want it to be accurate to.
If you don't understand the above it's fine. Here's a good explanation of where you guys can help;

The user inputs what decimal place they want to answer to be accurate to. If the user inputs let's say, 5 for the accuracy, then the function loop would keep doing the function until the decimal stops changing at that decimal. So since they picked 5, it would keep getting answers until the fifth decimal wasn't changing;
1.436326
1.423445
1.421432
1.421346
1.421353
1.421354
and then it would output that number in which the fifth decimal place did not change, along with how many times it had to run the function for it to get there. Is there anyway to compare the decimal places?
I'll let you respond to my post with the proper way to compare, but here's the way to extract the digit in the Nth decimal place of number X. Note that 'e' is the small-caps E that means 10^.


Code:
:XeN:Ans-10int(.1Ans
so X(10^n) for the first part basically right?
What is the Ans-10int(.1Ans part mean though? Looks confusing :s
joshie75 wrote:
so X(10^n) for the first part basically right?
What is the Ans-10int(.1Ans part mean though? Looks confusing :s
That's correct. That moves the decimal place over so that your target digit is in the ones place. The second part is what's called the modulus operator in computer science and math. A mod B (written A%B) is like dividing A by B and keeping the remainder. Examples:

13%10 = 3 (13/10 is 1 remainder 3)
45%5 = 0 (45/5 is 9 remainder 0)
2%1 = 0 (2/1 is 2 remainder 0; anything mod 1 is 0)
5%2 = 1 (5/2 is 2 remainder 1; great way to check for odd/even)
How does this modulus operator ( thank you for the thorough and awesome explanation of that by the way Smile ) fit into the second part?
Ans-10, would take the number from the Nth place and subtract 10. Is the "int(.1Ans" part the modulus operator?

EDIT: :OOO Kerm just blew my mind, thank you so much Kerm I fully understand, you rock Smile))
I went about this a little differently:

Code:
iPart(10fPart(XeN


I start by shifting the decimal point to a specified location with EN, as did Kerm. Let's say I have 314159.2654 after this transformation. 2 now is the target. If I lop off the integer part with fPart(—0.26535898—and multiply by ten—2.6535898—I'm left with the 2 in the one's place. Using iPart( gets me the 2 by itself.

Now, about this iteration: ƒ(x) = (3-ƒ(x-1))/2

Although this sequence converges, the leading digit will never settle. The dancing around both sides of an integer is because of a sign change in the expression. In cases like this, I think you should reassess how you measure tolerance.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement