# # figureitout1 := function() { include 'fitting.g' include 'pgplotter.g' t1 := tablefromascii('test1', 'PROFILE1',,T) x1 := t1.getcol('Column1'); y1 := t1.getcol('Column2'); x := x1[(x1 < 1.4)] - 1.2; y := y1[(x1 < 1.4)] -.11; myfit1 := fitter(); myfit1.init(n=5); myfit1.makepoly(x, y); myfit1.fit(); sol := myfit1.solution(); err := myfit1.error(); print 'Solution = ', sol; print 'Errors = ', err; xfit := [-160:200] /1000; yfit := sol[1] + sol[2]*xfit + sol[3]*xfit*xfit + sol[4]*xfit*xfit*xfit + sol[5]*xfit*xfit*xfit*xfit; myfit1.done(); mypg:=pgplotter(); mypg.plotxy(x=x, y=y, plotlines=F, xtitle='X', ytitle='Y', title='Y vs. X'); mypg.plotxy(x=xfit, y=yfit, plotlines=T, newplot=F, linecolor=3); # velocity, acceleration, jerk #vfit := sol[2] + 2*sol[3]*xfit + 3*sol[4]*xfit*xfit + 4*sol[5]*xfit*xfit*xfit; #afit := 2*sol[3] + 6*sol[4]*xfit + 12*sol[5]*xfit*xfit; #jfit := 6*sol[4] + 24*sol[5]*xfit #jerkmax := max(abs(jfit)) #print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; dt := xfit[2] - xfit[1]; xforv := ( xfit[1:(len(xfit)-1)] + xfit[2:len(xfit)] ) / 2.0; vel := ( yfit[2:len(yfit)] - yfit[1:(len(yfit)-1)] ) / dt; xfora := ( xforv[1:(len(xforv)-1)] + xforv[2:len(xforv)] ) / 2.0; acc := (vel[2:len(vel)] - vel[1:(len(vel)-1)] ) / dt; xforj := ( xfora[1:(len(xfora)-1)] + xfora[2:len(xfora)] ) / 2.0; jerk := ( acc[2:len(acc)] - acc[1:(len(acc)-1)] ) / dt; jerkmax := max(abs(jerk)) print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; x := -(x1[(x1 > 1.5)] -1.7); y := -(y1[(x1 > 1.5)] -1.4); myfit1 := fitter(); myfit1.init(n=5); myfit1.makepoly(x, y); myfit1.fit(); sol := myfit1.solution(); err := myfit1.error(); print 'Solution = ', sol; print 'Errors = ', err; xfit := [-150:150] /1000; yfit := sol[1] + sol[2]*xfit + sol[3]*xfit*xfit + sol[4]*xfit*xfit*xfit + sol[5]*xfit*xfit*xfit*xfit; myfit1.done(); mypg.plotxy(x=x, y=y, plotlines=F, xtitle='X', ytitle='Y', title='Y vs. X'); mypg.plotxy(x=xfit, y=yfit, plotlines=T, newplot=F, linecolor=3); # velocity, acceleration, jerk vfit := sol[2] + 2*sol[3]*xfit + 3*sol[4]*xfit*xfit + 4*sol[5]*xfit*xfit*xfit; afit := 2*sol[3] + 6*sol[4]*xfit + 12*sol[5]*xfit*xfit; jfit := 6*sol[4] + 24*sol[5]*xfit jerkmax := max(abs(jfit)) print 'Maximum Jerk for second half of 1.5 s: ', jerkmax; dt := xfit[2] - xfit[1]; xforv := ( xfit[1:(len(xfit)-1)] + xfit[2:len(xfit)] ) / 2.0; vel := ( yfit[2:len(yfit)] - yfit[1:(len(yfit)-1)] ) / dt; xfora := ( xforv[1:(len(xforv)-1)] + xforv[2:len(xforv)] ) / 2.0; acc := (vel[2:len(vel)] - vel[1:(len(vel)-1)] ) / dt; xforj := ( xfora[1:(len(xfora)-1)] + xfora[2:len(xfora)] ) / 2.0; jerk := ( acc[2:len(acc)] - acc[1:(len(acc)-1)] ) / dt; jerkmax := max(abs(jerk)) print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; } # # figureitout2 := function() { include 'fitting.g' include 'pgplotter.g' t1 := tablefromascii('test2', 'PROFILE2',,T) x1 := t1.getcol('Column1'); y1 := t1.getcol('Column2'); x := x1[(x1 < 1.5)]-1.25; y := y1[(x1 < 1.5)]-0.09; myfit1 := fitter(); myfit1.init(n=5); myfit1.makepoly(x, y); myfit1.fit(); sol := myfit1.solution(); err := myfit1.error(); print 'Solution = ', sol; print 'Errors = ', err; xfit := [-200:200] /1000; yfit := sol[1] + sol[2]*xfit + sol[3]*xfit*xfit + sol[4]*xfit*xfit*xfit + sol[5]*xfit*xfit*xfit*xfit; myfit1.done(); #mypg:=pgplotter(); mypg.plotxy(x=x, y=y, plotlines=F, xtitle='X', ytitle='Y', title='Y vs. X'); mypg.plotxy(x=xfit, y=yfit, plotlines=T, newplot=F, linecolor=3); # velocity, acceleration, jerk vfit := sol[2] + 2*sol[3]*xfit + 3*sol[4]*xfit*xfit + 4*sol[5]*xfit*xfit*xfit; afit := 2*sol[3] + 6*sol[4]*xfit + 12*sol[5]*xfit*xfit; jfit := 6*sol[4] + 24*sol[5]*xfit jerkmax := max(abs(jfit)) print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; dt := xfit[2] - xfit[1]; xforv := ( xfit[1:(len(xfit)-1)] + xfit[2:len(xfit)] ) / 2.0; vel := ( yfit[2:len(yfit)] - yfit[1:(len(yfit)-1)] ) / dt; xfora := ( xforv[1:(len(xforv)-1)] + xforv[2:len(xforv)] ) / 2.0; acc := (vel[2:len(vel)] - vel[1:(len(vel)-1)] ) / dt; xforj := ( xfora[1:(len(xfora)-1)] + xfora[2:len(xfora)] ) / 2.0; jerk := ( acc[2:len(acc)] - acc[1:(len(acc)-1)] ) / dt; jerkmax := max(abs(jerk)) print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; x := x1[(x1 > 2.0)] -2.25; y := y1[(x1 > 2.0)] -3.8; myfit1 := fitter(); myfit1.init(n=5); myfit1.makepoly(x, y); myfit1.fit(); sol := myfit1.solution(); err := myfit1.error(); print 'Solution = ', sol; print 'Errors = ', err; xfit := [-200:200] /1000; yfit := sol[1] + sol[2]*xfit + sol[3]*xfit*xfit + sol[4]*xfit*xfit*xfit + sol[5]*xfit*xfit*xfit*xfit; myfit1.done(); mypg.plotxy(x=x, y=y, plotlines=F, xtitle='X', ytitle='Y', title='Y vs. X'); mypg.plotxy(x=xfit, y=yfit, plotlines=T, newplot=F, linecolor=3); # velocity, acceleration, jerk vfit := sol[2] + 2*sol[3]*xfit + 3*sol[4]*xfit*xfit + 4*sol[5]*xfit*xfit*xfit; afit := 2*sol[3] + 6*sol[4]*xfit + 12*sol[5]*xfit*xfit; jfit := 6*sol[4] + 24*sol[5]*xfit jerkmax := max(abs(jfit)) print 'Maximum Jerk for second half of 1.5 s: ', jerkmax; dt := xfit[2] - xfit[1]; xforv := ( xfit[1:(len(xfit)-1)] + xfit[2:len(xfit)] ) / 2.0; vel := ( yfit[2:len(yfit)] - yfit[1:(len(yfit)-1)] ) / dt; xfora := ( xforv[1:(len(xforv)-1)] + xforv[2:len(xforv)] ) / 2.0; acc := (vel[2:len(vel)] - vel[1:(len(vel)-1)] ) / dt; xforj := ( xfora[1:(len(xfora)-1)] + xfora[2:len(xfora)] ) / 2.0; jerk := ( acc[2:len(acc)] - acc[1:(len(acc)-1)] ) / dt; jerkmax := max(abs(jerk)) print 'Maximum Jerk for first half of 1.5 s: ', jerkmax; }