Hello Thomas,
thank you for your response. I think, PLOT? would do it.
My usecase is a fit-program for expressions like
c1 + c2 * sin( C*x) + c3 * x + c4 * x^2 + ...
C is a nonlinear parameter which needs a SOLVE to be fitted. The linear ci parameters can be determined by the program COEFFIT which is given below in full length - for community and for discussion of further aspects later on (no claim for beauty, but it works)
Before start, the following - or a similar - expression should be defined in EQN-list:
MONOMS(X:C):[ 1 : SIN(C*X) : X : X*X : X*X*X : COS(X) ]
The NDATS x 2 matrix XYDATS should contain the data points to be fitted
NDEG = Number of summands to be used from MONOMS for the fit-expression
C = Value for the nonlin. parameter
As output, you will get the fit-error in X-reg. This error is a function of C.
SOLVE can be started for C to minimize the error resulting in a best fit.
To get an idea where to find the region for best fit (-> initial guess for C) a previous plot of error(C) is very useful. This is now, where PLOT? would give its value: To avoid, that VARMENU pops up.
BR
Dominik
LBL "COEFFIT"
MVAR "XYDATS"
MVAR "NDEG"
MVAR "C"
SKIP
"--SOLVERMODE?"
FS? 45
GTO A
-----
SKIP
"--PLOTMODE?"
PLOT?
GTO A
-----
VARMENU "COEFFIT"
STOP
EXITALL
FUNC 33
LBL A
SKIP
"--INIT NDATS"
RCL "XYDATS"
SKIP
"DIM? EATS X-RG"
DIM?
ROLL_DOWN
LSTO "NDATS"
SKIP
"--INIT MCOEFFS"
RCL "NDEG"
NEWMAT
LSTO "MCOEFFS"
SKIP
"--INIT YDATS"
RCL "NDATS"
1
NEWMAT
LSTO "XDATS"
LSTO "YDATS"
LSTO "INITVEC"
SKIP
"--START LOOP--"
SKIP
"--NDATS...3.2.1"
LBL 00
SKIP
XSTR "--GET DATS FROM XYDATS FRM BOTTOM UP"
SKIP
"GETMI KEEPS X;Y"
RCL "NDATS"
1
GETMI "XYDATS"
STO "X"
EVAL 'MONOMS(X:C)'
SKIP
"MONEVAL=Nx1"
LSTO "MONEVAL"
SKIP
"--MONVL->1xNDEG"
1
RCL "NDEG"
DIM "MONEVAL"
SKIP
"--INITVCxMONVL"
0
STO* "INITVEC"
RCL "NDATS"
1
1.0
PUTMI "INITVEC"
RCL "INITVEC"
RCL* "MONEVAL"
STO+ "MCOEFFS"
SKIP
"--GET Y-VAL"
RCL "NDATS"
2
GETMI "XYDATS"
RCL* "INITVEC"
STO+ "YDATS"
DSE "NDATS"
GTO 00
SKIP
"--LOOP END--"
SKIP
"--NDATS=0"
RCL "MCOEFFS"
LSTO "MTMCOEF"
TRANS
DUP
RCL* "MTMCOEF"
INVERT
X<>Y
RCL* "YDATS"
*
STO "FITCOFS"
SKIP
"...FOR Z-RG"
SKIP
"--PREDICT YDATS"
DUP
RCL "MCOEFFS"
X<>Y
*
RCL- "YDATS"
SKIP
"...FOR Y-RG"
SKIP
XSTR "--CALC RMS ERROR BY DOT NEEDS 1xNDATS"
DUP
TRANS
DUP
DOT
SQRT
SKIP
"...FOR X-RG"
END