Showing posts with label linear. Show all posts
Showing posts with label linear. Show all posts

Sunday, March 13, 2022

Casio fx-CG 50: Parametric Regression

Casio fx-CG 50:  Parametric Regression


Introduction


The program PARFIT2 attempts to pair data (x,y) using a pair of parametric equations [ x(t), y(t) ].   Each list of data will have its own curve.   


x(t), 1 ≤ t ≤ n

y(t), 1 ≤ t ≤ n

n = number of data points


Each point is assigned at t-value, which the program does automatically:

t = 1 refers to (x1, y1) → (t1, x1), (t1, y1)

t = 2 refers to (x2, y2) → (t2, x2), (t2, y2)

t = 3 refers to (x3, y3) → (t3, x3), (t3, y3)

and so on.


The program offers four regression types:


1.  Linear:  a + b*t

2.  Logarithm:  a + b*ln t

3.  Exponential:  a * b^t

4.  Power:  a * t^b


Variables used:


A = intercept for x(t)

B = slope for x(t)

R = correlation for x(t)


C = intercept for y(t)

D = slope for y(t)

S = correlation for y(t)


This allows for greater curve fitting control, which can accounts for different growth of the x data and y data, separately.


The program ends with a graph of the calculated parametric equation.  


Casio fx-CG 50 Program: PARTFIT


ClrText

Locate 1,1,"PARAMETRIC"

Locate 1,2,"FIT - 2022"

Locate 1,3,"EWS"

For 1→I To 750: Next

ParamType

ClrText

"X DATA"?→List 1

"Y DATA"?→List 2

Seq(x,x,1,Dim List 1, 1)→List 3


Menu "X=","A+BT",1,"A+Bln T",2,"A×B^T",3,"A×T^B",4

Lbl 1

LinearReg(a+bx) List 3, List 1

a→A: b→B: r→R

"A+BT"→Xt1

Goto 5

Lbl 2

LogReg List 3, List 1

a→A: b→B: r→R

"A+B×ln T"→Xt1

Goto 5

Lbl 3

ExpReg(a∙b^x) List 3, List 1

a→A: b→B: r→R

"A+B^T"→Xt1

Goto 5

Lbl 4

PowerReg List 3, List 1

a→A: b→B: r→R

"A+T^B"→Xt1

Goto 5

Lbl 5

"A, B, CORR=" ◢

[ [ A ] [ B ] [ R ] ] ◢


Menu "Y=","C+DT",A,"C+Dln T",B,"C×D^T",C,"C×T^D",D

Lbl A

LinearReg(a+bx) List 2, List 1

a→C: b→D: r→S

"C+DT"→Yt1

Goto E

Lbl B

LogReg List 2, List 1

a→C: b→D: r→S

"C+D×ln T"→Yt1

Goto E

Lbl C

ExpReg(a∙b^x) List 3, List 1

a→C: b→D: r→S

"C+D^T"→Yt1

Goto E

Lbl D

PowerReg List 3, List 1

a→C: b→D: r→S

"C+T^D"→Yt1

Goto E

Lbl E

"C, D, CORR=" ◢

[ [ C ] [ D ] [ S ] ] ◢


DrawGraph

ZoomAuto


Download the program here:  https://drive.google.com/file/d/1UVEHNZ7WILv3rSAgXy0_5kQ1lBPGEvKc/view?usp=sharing


Examples


Example 1:

(x,y):

(100.0, 10.0)

(101.3, 20.0)

(103.0, 31.7)

(104.3, 42.9)

(105.6, 54.2)

(107.0, 65.6)

(110.0, 77.0)


Fit x to linear and y to exponential.


Results:  

x(t) = 98.17142857 + 1.571428571*t,  corr = 0.9904886791

y(t) = 9.829695698 * 1.308085656^t, corr = 0.9639002639





Example 2:

(x,y):

(5.0, 0.41)

(2.9, 0.30)

(1.7, 0.20)

(0.9, 0.18)

(0.1, 0.12)


Fit x to logarithmic, y to power.


Results:  

x(t) = 5.002357022 - 3.010299732 * ln t, corr = -0.9997066364

y(t) = 0.4487684406* t^-0.7312889362,  corr = -0.9684707132




Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, November 29, 2020

HP Prime: Linear Exponential Combination Fit

 HP Prime:  Linear Exponential Combination Fit


The program LINEXPREG attempts to fit bivariate data to the curve:


y = a + b * x + c * e^x


The LSQ (least square) function is used.  The output is a list of three matrices:



*  A matrix of coefficients:  [ [ a ] [ b ] [ c ] ] 


*  A matrix of y values entered


*  A matrix of predicted y values



HP Prime Program LINEXPREG


EXPORT LINEXPREG(lx,ly)

BEGIN

// 2020-11-17 EWS

// x list, y list

LOCAL n,lx2,lx3,mx,my,k,mr,mq;

n:=SIZE(lx);

lx2:=e^(lx);

lx3:={};

FOR k FROM 1 TO n DO

lx3:=CONCAT(lx3,{1,lx(k),lx2(k)});

END;

mx:=list2mat(lx3,3);

my:=list2mat(ly,1);

mq:=LSQ(mx,my);

mr:=mq(1,1)+mq(2,1)*lx+

mq(3,1)*e^(lx);

mr:=list2mat(mr,1);

RETURN {mq,my,mr};

END;


Example





x list:  {0, 1, 2, 3, 4, 5}

y list:  {2, 7, 13, 18, 26, 34}


LINEXPREG({0, 1, 2, 3, 4, 5},{2, 7, 13, 18, 26, 34})


Results:  {coefficients, y values, predicted y values}


coefficients:

[ [ 1.74935499143 ]

[ 5.39455446221 ]

[ 3.66584105034E-2 ] ] 


y values:

[ [ 2 ]

[ 7 ]

[ 13 ]

[ 18 ]

[ 26 ]

[ 34 ] ]


predicted y values:

[ [  1.78601340193 ]

[ 7.24355734477 ]

[ 12.8093349675 ]

[ 18.6693222357 ]

[ 25.3290542368 ]

[ 34.1627178129 ] ] 


Equation:

y = 1.74935499143 + 5.39455446221 * x + 3.66584105034E-2 * e^x


On to the last month of 2020...


Eddie


All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Numworks (Python): Determining Earth’s Acceleration of Gravity

Numworks (Python): Determining Earth’s Acceleration of Gravity Introduction Note: We will only be using SI units on this blog en...