Polynomial prediction | Documentation | MentDB Weak
Goal
  • In mathematics, a polynomial function is a function obtained by evaluating a polynomial.
  • We are therefore going to try to find the coefficients of its corresponding polinomial function with coordinates.
  • So we can make predictions for a given value X.
  • Reminder, to execute an order, you can click on or or [CTRL]+E or [Apple]+E on OSX.
  • Here is a JSON array containing X, Y coordinates:
    "[
      [1.0, 2.0],
      [2.0, 2.5],
      [3.0, 2.8],
      [4.0, 2.9],
      [5.0, 3.1],
      [6.0, 3.5],
      [7.0, 3.9],
      [8.0, 4.0],
      [9.0, 4.1],
      [10.0, 4.3],
      [11.0, 4.35],
      [12.0, 4.36]
    ]"
    ;
  • Our goal is to recover the coefficients and make predictions.

Recovery of coefficients
  • First, load these coordinates into a variable:
    -> "[coordinates]" "[
      [1.0, 2.0],
      [2.0, 2.5],
      [3.0, 2.8],
      [4.0, 2.9],
      [5.0, 3.1],
      [6.0, 3.5],
      [7.0, 3.9],
      [8.0, 4.0],
      [9.0, 4.1],
      [10.0, 4.3],
      [11.0, 4.35],
      [12.0, 4.36]
    ]";
    
  • Let's see these coordinates. To do this, simply execute the command:
    pa xy_scatter [coordinates] "x, y";
    
  • Here are the coordinates displayed on an axis:
  • Let us execute the command which makes it possible to recover the coefficients. It will be necessary to pass to this command an additional parameter which is the maximum degree of the polynomial function (here: degree=3).
    pa polynomial_curve_fit_get_coeff [coordinates] "3";
    
  • The result:
    "[1.8082828282828278,0.2746072446072453,0.00898046398046389,-0.0011745661745661716]";
    
  • We got the coefficients.

Make prediction
  • Load these coefficients into a variable:
    -> "[coefficients]" (pa polynomial_curve_fit_get_coeff [coordinates] "3");
    
  • Let's try to reconstruct the function that uses these coefficients, starting from X = 1 to 12 and using an increment of 0.1:
    pa polynomial_curve_fit_eval_incr [coefficients] 1 12 0.1;
    
  • The result:
    "[[1.0,2.090695970695971],[1.1,2.1196538111888112],[1.2000000000000002,2.14871373959374],[1.3000000000000003,2.1778687085137087],[1.4000000000000004,2.207111670551671],[1.5000000000000004,2.2364355783105787],[1.6000000000000005,2.265833384393385],[1.7000000000000006,2.295298041403042],[1.8000000000000007,2.324822501942503],[1.9000000000000008,2.354399718614719],[2.000000000000001,2.384022644022645],[2.100000000000001,2.4136842307692317],[2.200000000000001,2.4433774314574324],[2.300000000000001,2.4730951986901997],[2.4000000000000012,2.5028304850704863],[2.5000000000000013,2.532576243201244],[2.6000000000000014,2.562325425685427],[2.7000000000000015,2.592070985125986],[2.8000000000000016,2.6218058741258754],[2.9000000000000017,2.6515230452880467],[3.0000000000000018,2.6812154512154525],[3.100000000000002,2.710876044511046],[3.200000000000002,2.7404977777777795],[3.300000000000002,2.770073603618605],[3.400000000000002,2.799596474636476],[3.500000000000002,2.829059343434345],[3.6000000000000023,2.858455162615164],[3.7000000000000024,2.8877768847818865],[3.8000000000000025,2.917017462537464],[3.9000000000000026,2.94616984848485],[4.000000000000003,2.975226995226997],[4.100000000000002,3.0041818553668573],[4.200000000000002,3.033027381507383],[4.300000000000002,3.0617565262515276],[4.400000000000001,3.090362242202244],[4.500000000000001,3.1188374819624833],[4.6000000000000005,3.1471751981351996],[4.7,3.1753683433233446],[4.8,3.203409870129871],[4.8999999999999995,3.231292731157732],[4.999999999999999,3.25900987900988],[5.099999999999999,3.286554266289267],[5.199999999999998,3.313918845598846],[5.299999999999998,3.34109656954157],[5.399999999999998,3.368080390720391],[5.499999999999997,3.394863261738262],[5.599999999999997,3.4214381351981356],[5.699999999999997,3.447797963702964],[5.799999999999996,3.4739356998557],[5.899999999999996,3.4998442962592966],[5.999999999999996,3.525516705516705],[6.099999999999995,3.5509458802308798],[6.199999999999995,3.576124773004773],[6.2999999999999945,3.601046336441336],[6.399999999999994,3.625703523143523],[6.499999999999994,3.6500892857142855],[6.599999999999993,3.674196576756576],[6.699999999999993,3.6980183488733482],[6.799999999999993,3.721547554667554],[6.899999999999992,3.744777146742146],[6.999999999999992,3.7677000777000766],[7.099999999999992,3.7903093001442993],[7.199999999999991,3.8125977666777655],[7.299999999999991,3.8345584299034288],[7.399999999999991,3.856184242424241],[7.49999999999999,3.8774681568431557],[7.59999999999999,3.8984031257631244],[7.6999999999999895,3.9189821017871003],[7.799999999999989,3.939198037518036],[7.899999999999989,3.9590438855588843],[7.9999999999999885,3.978512598512597],[8.099999999999989,3.9975971289821275],[8.199999999999989,4.016290429570428],[8.299999999999988,4.034585452880451],[8.399999999999988,4.05247515151515],[8.499999999999988,4.069952478077477],[8.599999999999987,4.087010385170384],[8.699999999999987,4.103641825396823],[8.799999999999986,4.11983975135975],[8.899999999999986,4.135597115662113],[8.999999999999986,4.150906870906869],[9.099999999999985,4.165761969696968],[9.199999999999985,4.180155364635363],[9.299999999999985,4.194080008325006],[9.399999999999984,4.207528853368851],[9.499999999999984,4.220494852369851],[9.599999999999984,4.232970957930956],[9.699999999999983,4.244950122655121],[9.799999999999983,4.256425299145297],[9.899999999999983,4.267389440004438],[9.999999999999982,4.277835497835497],[10.099999999999982,4.287756425241424],[10.199999999999982,4.297145174825173],[10.299999999999981,4.305994699189698],[10.39999999999998,4.3142979509379495],[10.49999999999998,4.322047882672881],[10.59999999999998,4.329237446997446],[10.69999999999998,4.335859596514595],[10.79999999999998,4.3419072838272825],[10.899999999999979,4.34737346153846],[10.999999999999979,4.352251082251081],[11.099999999999978,4.356533098568098],[11.199999999999978,4.360212463092463],[11.299999999999978,4.3632821284271275],[11.399999999999977,4.365735047175047],[11.499999999999977,4.367564171939172],[11.599999999999977,4.3687624553224556],[11.699999999999976,4.369322849927849],[11.799999999999976,4.369238308358308],[11.899999999999975,4.368501783216783],[11.999999999999975,4.367106227106227]]"
    ;
  • Let's see the fonction. To do this, simply execute the command:
    pa xy_scatter (pa polynomial_curve_fit_eval_incr [coefficients] 1 12 0.1) "X, Y";
    
  • Here are the fonction displayed on an axis:
  • We can see that the function and the departure coordinates are really very close.
  • Let's test with another greater degree (5):
    pa xy_scatter (pa polynomial_curve_fit_eval_incr (pa polynomial_curve_fit_get_coeff [coordinates] 5) 1 12 0.1) "X, Y";
    
  • Here are the fonction displayed on an axis:
  • We are even closer.
  • Quel est le Y prédit par cette dernière fonction pour X=7.21:
    pa polynomial_curve_fit_eval (pa polynomial_curve_fit_get_coeff [coordinates] 5) 7.21;
    
  • The result:
    "3.829253240846826"
    ;
  • You now know how to run polynomial predictions.
  • W103 - Polynomial prediction


MentDB © 2012 - 2020 - Legal Notice