Flag for prog-call from within plot app

27 views
Skip to first unread message

Blaubeer Marmelade

unread,
Mar 9, 2026, 3:28:45 PM (2 days ago) Mar 9
to Free42 & Plus42
Hello all,
As you know, the plot application in plus42 can iteratively call a prg to calculate the function values. If there is a varmenu in this prg however, it should be bypassed if called for plot.
Is it possible to recognize from within a prg, if it is called by plot app?
As an example: the prog call from solver app can be checked by ...SF? 45...
BR
Dominik

Thomas Okken

unread,
Mar 9, 2026, 6:50:49 PM (2 days ago) Mar 9
to Free42 & Plus42
The numbered flags are already all in use, but I could add a function PLOT? to allow checking whether PLOT is active.

I'm not sure I understand the use case, though. PLOT is more flexible than SOLVE and INTEG in how it handles parameters and return values, so the need for this PLOT? feature isn't clear to me. Could you give an example where this would be used?

Blaubeer Marmelade

unread,
Mar 10, 2026, 5:00:03 PM (22 hours ago) Mar 10
to Free42 & Plus42
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


Reply all
Reply to author
Forward
0 new messages