Grr, deleted line in Newton's Method program

In summary, a user was seeking help with recovering a deleted line of code in their TI-83 Plus calculator program. The program was for Newton's Method and used the Y1 and Y2 functions to calculate derivatives. The missing line was revealed to be "Disp X Pause" and a suggestion was made to use the nDeriv function. The user expressed concern about the slower convergence rate of the secant method used by nDeriv and asked for clarification on how to input Y1 and Y2 functions. The conversation concluded with a discussion on the merits of using nDeriv versus manually calculating derivatives.
  • #1
Coldie
84
0
Hi, I've done something really stupid. I found a Newton's Method program on the internet and copied it to my TI-83 Plus. This program let you put the function in Y1 and its derivative in Y2. Then, you ran the program, and once you input your first guess, you would hit the ENTER key as many times as you wanted and it would continue to guess the next number. However, the program had no end, and so you'd have to hit the "ON" button to stop it, which resulted in the ERR:BREAK message. So, today, I was using the program, and when I hit the ON button to end it, I accidentally hit "Goto" instead of "Quit" in the message that came up, and, before I could stop myself, hit "CLEAR" to clear the window, but instead deleted a line of code.

Here's what remains of the program:
Prompt X
Lbl 0
X-Y1(X)/Y2(X)->X
(deleted line)
Goto 0

Can someone tell me what was in that line, please?
 
Physics news on Phys.org
  • #2
That's probably where you want to add a segment of code to allow you to exit the program. I assume this because without such a segment, the program would go into an infinite loop.

I'd add something like this:

---------
ClearHome
Output(1,1,X
Output(1,3, "Calculate another iteration? Y/N"
Prompt A
If A = "Y"
Then
Stop
Else
Goto 0
 
Last edited by a moderator:
  • #3
P.S. You can add another segment so you don't have to calculate the derivative into Y2. Add this in the beginning of your program.

-----
nDeriv(Y1,X,X) -> Y2
 
  • #4
It WAS an infinite loop, and I'd prefer that it be kept that way so that I don't have to go through one extra step before it calculates the next number for me. Thank you for going to such lengths in telling me how I could improve the program, but could you simply guess what the line of code that I deleted was? As I mentioned, it would calculate one, then wait for the ENTER key to be pressed before calculating another. You pressed the ON key to exit the program, and all I want is for it to work like that again.

[edit]
Thanks for the second part, I think I will put that in.
 
Last edited:
  • #5
It still is an infinite loop, I just allowed you to actually say if you wanted to stop without manually stopping the program with a "BREAK". I don't understand why you want it the other way... that way honestly seems worse... but as you wish.

The missing code was
-------
Disp X
Pause
 
  • #6
Thank you very much for your help! I don't understand how I managed to delete two lines of code, but it works just like before!

If you could just tell me one more thing I'd be very grateful... how do you input things like Y1 and Y2? I seem to have forgotten where to get them as it was quite a long time that I wrote the program in.
 
  • #7
Goto VARS... it may be a 2nd funtion (i don't have my calculator right in front of me).
There you should find something called "Y-VARS". Click that and pick the one you want.


Jameson
 
  • #8
Y-VARS, Function. Thanks again for all the help!
 
  • #9
Um, sorry, but I'm getting ERR:DATA TYPE with that line that you told me to add...
 
  • #10
Which line?
 
  • #11
Make sure type in "nDeriv(Y2,X,X"

For Y2, goto the VARS button like we talked about...
 
  • #12
That's the line.

nDeriv(Y1,X,X)->Y2, with both Y's entered via the VARS button.
 
  • #13
are you hitting the "STORE" button... the one that looks like STO?


EDIT: It looks like "->" this, but on the calculator it looks like "STO ->"
 
  • #14
Sorry for the delay. Yes, I am, I know the syntax exactly and I've compared it with another program and it looks fine. Could you test it out on yours and tell me if it works?
 
  • #15
Did you have an equation into Y1 before you ran the program?
 
  • #16
Using the nDeriv function will slow down the program a great deal. May as well just calculate the derivative yourself and program it in.

--J
 
  • #17
Yes it will, but if the derivative is not so easy to compute, you may just want to let the calculator do it. It really doesn't take that long, only when you have to graph it.
 
  • #18
I looked at the 83's documentation, and the nDeriv() function uses the secant method to calculate the derivative at a point, i.e.

[tex]f'(a) = \frac{f(a + \epsilon) - f(a - \epsilon)}{2\epsilon}[/tex]

where [itex]\epsilon[/itex] is defaulted to 10-3, but can be specified.

Because of this, using nDeriv to calculate the derivative makes the entire algorithm the secant method instead of the Newton-Raphson, so it will converge a bit more slowly (on the order of the golden ratio instead of quadratically). Additionally, the secant method is a little bit slower, since it needs to calculate two extra values before it can get the derivative (f(a ± epsilon)). It's a tradeoff between having to calculate the derivative and how quickly you want it to converge and a bit of processing time. If you're controlling the iterations manually, you'll never notice the processing time, so it's down to convergence.

If you're tested on the Newton-Raphson method and you use the nDeriv function, you'll most likely get the wrong answer. Then again, if it's just for your own purposes and you don't throw any particularly misbehaved functions at it, the secant (nDeriv) method will be more than sufficient.

Or you could just program in both.

--J
 
  • #19
Where did you find that the 83 uses a secant method? I've used it to calculate many derivatives that were exactly correct. Did you find this in the manual, and if so, what page?
 
  • #20
http://education.ti.com/downloads/guidebooks/eng/83m$book-eng.pdf

Page 70 explains the nDeriv function.

There are times that the secant method will give the exact slope. For instance, if f(x) = x2, then the formula used to calculate slope reduces to 2x, regardless of the epsilon.

--J
 
Last edited by a moderator:
  • #21
Wow, I didn't know that. Thanks for the link. So I guess if you want to use nDeriv for the program you should write the code:

nDeriv(Y1,X,X,1^-7) -> Y2

--------
Or something to that extent, where the approximation will be close. You could even enter a little code to ask whether you want to enter the derivative manually or not.

-------
Lbl 1
ClearHome
Disp "Enter derivative manually?"
Prompt A
If A = "YES"
Then
Goto Lbl 3
Else
Goto Lbl 2
Stop

Lbl 2
nDeriv(Y1,X,X,1^-7) ->Y2
Goto 4

Lbl 3
Disp "Enter derivative"
Prompt D
D -> Y2
Goto 4

Lbl 4

..... Rest of code


Jameson
 

Related to Grr, deleted line in Newton's Method program

1. Why is there a "deleted line" in my Newton's Method program?

This could be due to a few reasons. It is possible that you accidentally deleted a necessary line while editing the code. It could also be a result of a coding error or a bug in the program. Double check your code and make sure all necessary lines are included.

2. How do I fix the "deleted line" in my Newton's Method program?

First, try to identify where the deleted line was located and what its purpose was in the program. Then, either restore the line or find an alternative way to achieve the same result. If you are unsure, seek help from a more experienced programmer or consult online resources for troubleshooting tips.

3. Will the "deleted line" affect the accuracy of my Newton's Method program?

It depends on the specific line that was deleted. If it was a crucial step in the algorithm, then it could significantly impact the accuracy of the program. However, if it was a minor line or a duplicate line, the impact may be minimal. It is always best to thoroughly test your program after making any changes to ensure its accuracy.

4. Can I prevent accidentally deleting lines in my Newton's Method program?

Yes, there are a few ways to prevent this from happening. One way is to make regular backups of your code so you can easily restore previous versions if needed. You can also use version control systems like Git to track changes and revert back to previous versions. Additionally, being cautious and double-checking your code before making any changes can also help prevent accidental deletions.

5. How can I improve my Newton's Method program to avoid "deleted line" errors in the future?

To avoid "deleted line" errors, it is important to have a good understanding of the code and the purpose of each line. Commenting your code and using clear and descriptive variable names can also help prevent confusion and accidental deletions. Additionally, regularly testing and debugging your code can help catch any errors before they become a bigger issue.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • General Math
Replies
16
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
849
  • Programming and Computer Science
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
Replies
1
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
5K
Back
Top