Post Reply 
(15C) Nth Degree Polynomial Program
12-03-2019, 01:42 AM (This post was last modified: 12-15-2022 02:55 AM by Gene.)
Post: #1
(15C) Nth Degree Polynomial Program
Hello all, this program calculates a y value for any degree polynomial (between 1 and 56 theoretically, or more with a memory expansion) given an x value and matrix A containing the coefficients of the expression. This is useful for using the SOLVE and ∫yx functions, and for using Linear regression to plot secant lines. The program uses Horner's Method, which is outlined on pg. 79 of the latest 15c manual. Unfortunately, this program completely obliterates the stack so don't put anything important in there!

If you're keying this program in manually; be mindful of the USER mode instructions. A handy trick for keying the program in at some location other than 000 is to add however many R/S instructions is necessary to make the line number a multiple of 10, making it much easier to compare line numbers and ensure accurate entry. Once finished (leave them in until after a test run) you may optionally execute GTO A in run mode followed by a BST in program mode to easily position the cursor on the extraneous instructions for removal.

Usage
  • Dimension matrix A such that the area is equal to the degree of the desired polynomial. The shape of the matrix doesn't matter. For instance, a 1x6 matrix works just the same as a 2x3 matrix. The program uses the area to automatically calculate the degree of the expression.
  • As an aside, the area of a matrix is obtained with RCL DIM [A-E], multiply.
  • Fill the matrix with the polynomial cooeficients, with the most significant term at (1,1), in decending order
  • key a value into X and run the program by calling label A. (remember you're probably already in user mode)

Code:

   001 {    42 21 11 } f LBL A
   002 {    42 16  1 } f MATRIX 1
   003 {    45 23 11 } RCL DIM A
   004 {          20 } ×
   005 {           2 } 2
   006 {    43 30  9 } g TEST x≥y
   007 {    22 48  8 } GTO .8
   008 {          30 } −
   009 {    44 48  9 } STO .9
   010 {    32 48  6 } GSB .6
   011 {    45 11  u } RCL A
   012 {          20 } ×
   013 { 42 21 48  9 } f LBL .9
   014 {    45 11  u } RCL A
   015 {          40 } +
   016 {          20 } ×
   017 { 42  5 48  9 } f DSE .9
   018 {    22 48  9 } GTO .9
   019 {          36 } ENTER
   020 {    45 11  u } RCL A
   021 {          40 } +
   022 {          40 } +
   023 {       43 32 } g RTN
   024 { 42 21 48  8 } f LBL .8
   025 {       43 35 } g CLx
   026 {           1 } 1
   027 {       43 10 } g x≤y
   028 {    22 48  7 } GTO .7
   029 {          33 } R⬇
   030 {    32 48  6 } GSB .6
   031 {    45 11  u } RCL A
   032 {          20 } ×
   033 {       45 11 } RCL A
   034 {          40 } +
   035 {       43 32 } g RTN
   036 { 42 21 48  7 } f LBL .7
   037 {          33 } R⬇
   038 {    32 48  6 } GSB .6
   039 {       45 11 } RCL A
   030 {       43 32 } g RTN
   031 { 42 21 48  6 } f LBL .6
   032 {          33 } R⬇
   033 {          36 } ENTER
   034 {          36 } ENTER
   035 {          36 } ENTER
   036 {       43 32 } g RTN

if you're using this 15c emulator and a DM15, you can simply copy this code as-is into a .15c file and upload it. Hope you enjoy!!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(15C) Nth Degree Polynomial Program - 15-lennyphelan - 12-03-2019 01:42 AM



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