CW%APG.PH.UCL.AC.UK@pucc.PRINCETON.EDU (04/13/91)
Dear Hekrik, I will try to be breif because I'm in a hurry. I'm very happy with your least squares routine LSQ. I have needed one of these ever since I have had my 48sx!!! There is only one thing I think might make it a bit better. Instead of EVAL at a certain point I have used ->NUM (see listing below), this means that algebraics like 'eX' will work in the list (in the eval form a number is not returned by EVAL for algebraics using things like 'e'), and it forces a number to be returned (if possible) whatever the form of the equation. This is in no way a criticism, but rather my experience with the routine (I never use the EXP() form to enter exponentials). Here is the one simple change.... %%HP: T(3)A(R)F(.); \<< \<< IF DUP SIZE SIZE 1 == THEN OBJ\-> 1 SWAP + \->ARRY TRN CONJ END \>> \-> fix \<< IF DUP TYPE 5 \=/ THEN 1 \->LIST END 4 ROLL fix EVAL DUP SIZE OBJ\-> DROP \-> yv fv vv xv r c \<< IF r yv SIZE 1 GET - c vv SIZE - OR THEN "Size(s) mismatch" DOERR END 1 fv SIZE FOR I xv OBJ\-> DROP fv I GET \-> f \<< r 1 FOR J vv OBJ\-> DROP 1 c FOR K c 2 + K - ROLL SWAP STO NEXT f \->NUM J 1 - c * 1 + @CHANGED IT HERE r + J - ROLLD -1 STEP \>> NEXT fv SIZE r 2 \->LIST \->ARRY DUP yv fix EVAL DUP 4 ROLLD * DUP 4 ROLLD SWAP DUP TRN CONJ * / DUP 4 ROLLD TRN CONJ SWAP 3 ROLLD SWAP * OBJ\-> DROP SWAP DUP 1 CON TRN SWAP * OBJ\-> DROP SQ r / SWAP OVER - SWAP yv DUP DOT - NEG / SWAP IF -3 FC? THEN \-> cv \<< 0 1 fv SIZE FOR I cv I 1 2 \->LIST GET fv I GET * + NEXT \>> END \>> \>> \>> Do you think this changes the results in any erroneous way? Thankyou for an excellent routine that I have already found very useful, Conrad