Combine Export and Local variables? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Combine Export and Local variables? (/thread-18186.html) Combine Export and Local variables? - Amer7 - 03-28-2022 09:47 AM Hello, I have this matrix program. Idea: 1.) I will use default calculator matrix editor to input values into Matrix M1,M2,M3 2.) At the beginning of the program I want to use Input command to input a 2 variables. Their values are later used in the calculation in few places. Issue: I want to Export new Matrices ( N1,U1,Q1,D1,V1,L1, K1,K2, F1,S0,X1,K3,C1,C2,Q2,C3,Q3,Q4) so I could easily view their values in default calculator matrix editor. In past I have used this idea that you suggested, and it worked great. Code: ``` //PROGRAM START EXPORT A1,A2; EXPORT function1 () BEGIN A1:=M1+M1; A2:=M1-M1; END;``` But now I don't know how to combine these two. Everything I've tried i get an error. Program that I want local to be exported Code: ``` EXPORT TST() BEGIN LOCAL w1,w2; INPUT({w1,w2},"Prekobrojnost", {"Unesi prekobrojnost u","Unesi srednju vrijednost xo"}); LOCAL N1,U1,Q1,D1,V1,L1; //N1- matica normalnih jednacina //U1, Q1 - kofaktor matrica //D1- vektor popravaka nepoznatih parametara //V1-Vektor popravaka mjerenja N1:=TRN(M1)*M2*M1; U1:=TRN(M1)*M2*M3; Q1:=inv(N1); D1:=-(Q1*U1); V1:=(M1*D1)+M3; L1:=TRN(V1)*M2*V1; LOCAL K1,K2; //K1 - kontrola 1.) popravaka treba biti =0 K1:=TRN(M1)*M2*V1; //K2 - Kontrola 2.) izjedacenja treba biti = lambdi K2:=TRN(M3)*M2*V1; LOCAL F1,S0,X1,K3; F1:=(1/w1)*L1; S0:=SQRT(F1(1,1)); X1=w2+D1; // Popravljena mjerenja su pojedinacna l1,l2,l3...+ matrica V1; K3:=M1*X1; ///Stohasticki dio LOCAL C1,C2,Q2,C3; C1:=F1*Q1; // Deviacija mjerenja tako sto uzmemo korjen od Cx C2:=F1*inv(M2); //C2 - tacnost mjerenja // srednje greske izvucem iz cl matrice korjen(dijagonalnih) Q2:=M1*Q1*TRN(M1); C3:=Q2*F1(1,1); ///Srednje greške popravljenih korjen dijagonale clanova C3 LOCAL Q3,Q4; Q3:=inv(M2)-Q2; Q4:=F1(1,1)*Q3; PRINT("Kontrola K1 =0"+K1); IF (K2=L1) THEN PRINT ("Kontrola 2 OK!"); END; END;``` And is there any way I could highlight In color this IF (K2==L1) THEN PRINT ("Kontrola 2 OK!"); If the K2 is equal to L1, and in red it it's not. ( printout in terminal) ? RE: Combine Export and Local variables? - toml_12953 - 03-28-2022 10:20 AM (03-28-2022 09:47 AM)Amer7 Wrote:  Hello, I have this matrix program. Idea: 1.) I will use default calculator matrix editor to input values into Matrix M1,M2,M3 2.) At the beginning of the program I want to use Input command to input a 2 variables. Their values are later used in the calculation in few places. Issue: I want to Export new Matrices ( N1,U1,Q1,D1,V1,L1, K1,K2, F1,S0,X1,K3,C1,C2,Q2,C3,Q3,Q4) so I could easily view their values in default calculator matrix editor. In past I have used this idea that you suggested, and it worked great. Code: ``` //PROGRAM START EXPORT A1,A2; EXPORT function1 () BEGIN A1:=M1+M1; A2:=M1-M1; END;``` But now I don't know how to combine these two. Everything I've tried i get an error. Program that I want local to be exported Code: ``` EXPORT TST() BEGIN LOCAL w1,w2; INPUT({w1,w2},"Prekobrojnost", {"Unesi prekobrojnost u","Unesi srednju vrijednost xo"}); LOCAL N1,U1,Q1,D1,V1,L1; //N1- matica normalnih jednacina //U1, Q1 - kofaktor matrica //D1- vektor popravaka nepoznatih parametara //V1-Vektor popravaka mjerenja N1:=TRN(M1)*M2*M1; U1:=TRN(M1)*M2*M3; Q1:=inv(N1); D1:=-(Q1*U1); V1:=(M1*D1)+M3; L1:=TRN(V1)*M2*V1; LOCAL K1,K2; //K1 - kontrola 1.) popravaka treba biti =0 K1:=TRN(M1)*M2*V1; //K2 - Kontrola 2.) izjedacenja treba biti = lambdi K2:=TRN(M3)*M2*V1; LOCAL F1,S0,X1,K3; F1:=(1/w1)*L1; S0:=SQRT(F1(1,1)); X1=w2+D1; // Popravljena mjerenja su pojedinacna l1,l2,l3...+ matrica V1; K3:=M1*X1; ///Stohasticki dio LOCAL C1,C2,Q2,C3; C1:=F1*Q1; // Deviacija mjerenja tako sto uzmemo korjen od Cx C2:=F1*inv(M2); //C2 - tacnost mjerenja // srednje greske izvucem iz cl matrice korjen(dijagonalnih) Q2:=M1*Q1*TRN(M1); C3:=Q2*F1(1,1); ///Srednje greške popravljenih korjen dijagonale clanova C3 LOCAL Q3,Q4; Q3:=inv(M2)-Q2; Q4:=F1(1,1)*Q3; PRINT("Kontrola K1 =0"+K1); IF (K2=L1) THEN PRINT ("Kontrola 2 OK!"); END; END;``` And is there any way I could highlight In color this IF (K2==L1) THEN PRINT ("Kontrola 2 OK!"); If the K2 is equal to L1, and in red it it's not. ( printout in terminal) ? How does it know those local variables (N1,U1, etc.) are matrices unless you reserve space for them with MAKEMAT or MAKELIST? RE: Combine Export and Local variables? - Amer7 - 03-28-2022 10:48 AM Well I'm not sure, If the start value is Matrix, and if there are two operations with matrices it considers it automatically to be a matrix? Code: ```//PROGRAM START EXPORT A1,A2; EXPORT function1 () BEGIN A1:=M1+M1; A2:=M1-M1;``` When I used this code, I didn't reserve it with MAKEMAT or MAKELIST And the A1, and A2 matrices appeared in matrix editor with correct values RE: Combine Export and Local variables? - Amer7 - 03-29-2022 11:00 AM I have figured how to combine, It all works until the calculation between local and global variable. Code: ``` //PROGRAM START EXPORT N1,U1,Q1,D1,V1,V2,K1,K2; EXPORT K3,F1,S0,X1,C1,C2,C3,Q3; EXPORT Q2,Q4; EXPORT function1 () BEGIN LOCAL w1,w2; INPUT({w1,w2},"Prekobrojnost", {"Unesi prekobrojnost u","Unesi srednju vrijednost xo"}); N1:=TRN(M1)*M2*M1; U1:=TRN(M1)*M2*M3; Q1:=inv(N1); D1:=-(Q1*U1); V1:=(M1*D1)+M3; V2:=TRN(V1)*M2*V1; //K1 - kontrola 1.) popravaka treba biti =0 K1:=TRN(M1)*M2*V1; //K2 - Kontrola 2.) izjedacenja treba biti = lambdi K2:=TRN(M3)*M2*V1; F1:=(V2/w1); S0:=SQRT(F1(1,1)); --- The program WORKS UNTIl here  X1=w2+D1; // Popravljena mjerenja su pojedinacna l1,l2,l3...+ matrica V1; K3:=M1*X1; ///Stohasticki dio C1:=F1*Q1; // Deviacija mjerenja tako sto uzmemo korjen od Cx C2:=F1*inv(M2); //C2 - tacnost mjerenja // srednje greske izvucem iz cl matrice korjen(dijagonalnih) Q2:=M1*Q1*TRN(M1); C3:=Q2*F1(1,1); ///Srednje greške popravljenih korjen dijagonale clanova C3 Q3:=inv(M2)-Q2; Q4:=F1(1,1)*Q3; PRINT("Kontrola K1 =0"+K1); IF (K2=V2) THEN PRINT ("Kontrola 2 OK!"); END; END;``` The program returns 0, starting with Blolded part of the code- And that is not correct. RE: Combine Export and Local variables? - roadrunner - 03-29-2022 12:11 PM This line: X1=w2+D1; should be this: X1:=w2+D1; -road RE: Combine Export and Local variables? - Amer7 - 03-29-2022 12:57 PM (03-29-2022 12:11 PM)roadrunner Wrote:  This line: X1=w2+D1; should be this: X1:=w2+D1; -road Thank you road, I don't know how I didn't spot that. Is there a way that I could label the matrix in matrix editor? What I mean Can I somehow add text (description) Like Q3 is Matrix of average deviation of corrected measurements. Instead of having just Q3 and number of rows and columns [attachment=10486] RE: Combine Export and Local variables? - roadrunner - 03-29-2022 01:52 PM Did you try EDITMAT: EDITMAT(Q3,"this is the title for Q3"); ? RE: Combine Export and Local variables? - Amer7 - 03-29-2022 02:11 PM (03-29-2022 01:52 PM)roadrunner Wrote:  Did you try EDITMAT: EDITMAT(Q3,"this is the title for Q3"); ? Yes I have, but when I run the program it displays the Matrices with their titles, one by one. ( if i write EDITMAT for Q3, EDITMAT for Q4) (I've added the EDITMAT at the bottom of the program) Run program: Q3 with it's title ->OK ->Q4 with it's title ->OK-> Terminal But when I go to Matrix editor and click to view matrix Q3 there is no tittle. When I go Vars-User-Program Variables-Q3 It displays the matrix values in home. Is there any way simple way I could keep the Matrix with Title and their values for later viewing? And I have an issue when I clear the User variables, in matrix editor I still get matrices Q3, Q4... but empty (1,1) [attachment=10487] Edit: If it's complicated I will just return to using Local variable with EDIT MAT, and re-run program to see the value of the Matrix i need. RE: Combine Export and Local variables? - roadrunner - 03-29-2022 02:36 PM (03-29-2022 02:11 PM)Amer7 Wrote:  Is there any way simple way I could keep the Matrix with Title and their values for later viewing? Not that i know of, at least not without writing a subroutine specifically for that; but someone else may know better. I also noticed some of your variable names are reserved names. Generally I try to avoid using reserved names in programs because it can sometimes cause issues. To avoid issues you can add a lower case letter to each variable name; for example: Uu1 instead of U1. -road RE: Combine Export and Local variables? - Amer7 - 03-29-2022 02:55 PM Thank you road, you guys really helped me write simple programs for this calculator. I will implement the suggestion. Thank you! RE: Combine Export and Local variables? - Amer7 - 04-11-2022 09:58 AM Does anyone has an idea why the program crasher mid way with error Invalid input INPUT({ff7,gg7},"Input test", {"Prekobrojnost","Sredina"}); Code: ``` //PROGRAM START LOCAL Nn1,Uu1,Qq1,Dd1,Vv1,Vv2,Kk1,Kk2; LOCAL Kk3,Ff1,Ss0,Xx1,Cc1,Cc2,Cc3,Qq3; LOCAL Qq2,Qq4,Pm1,Sx1; EXPORT function1 () BEGIN LOCAL ff7,gg7; INPUT({ff7,gg7},"Input test", {"Prekobrojnost","Sredina"}); Nn1:=TRN(M1)*M2*M1; Uu1:=TRN(M1)*M2*M3; Qq1:=inv(Nn1); Dd1:=-(Qq1*Uu1); Vv1:=(M1*Dd1)+M3; Vv2:=TRN(Vv1)*M2*Vv1; //K1 - kontrola 1.) popravaka treba biti =0 Kk1:=TRN(M1)*M2*Vv1; //K2 - Kontrola 2.) izjedacenja treba biti = lambdi Kk2:=TRN(M3)*M2*Vv1; Ff1:=Vv2/(ff7); Ss0:=SQRT(Ff1(1,1)); Xx1:=gg7+Dd1(1,1); // Popravljena mjerenja su pojedinacna l1,l2,l3...+ matrica V1; Kk3:=M1*Xx1; Pm1:=M4+Vv1; ///Stohasticki dio Cc1:=Ff1(1,1)*Qq1; Sx1:=SQRT(Cc1(1,1)); // Deviacija mjerenja tako sto uzmemo korjen od Cx Cc2:=Ff1(1,1)*inv(M2); //C2 - tacnost mjerenja // srednje greske izvucem iz cl matrice korjen(dijagonalnih) Qq2:=M1*Qq1*TRN(M1); Cc3:=Qq2*Ff1(1,1); ///Srednje greške popravljenih korjen dijagonale clanova C3 Qq3:=inv(M2)-Qq2; Qq4:=Ff1(1,1)*Qq3; /// ISPISI MATRICA EDITMAT(Nn1,"Matrica Normalnih jednacina"); EDITMAT(Uu1,"u=trn(A)*P*w"); EDITMAT(Qq1,"Kofaktorna matrica"); EDITMAT(Dd1,"vektor popravaka nepoznatih"); EDITMAT(Vv1,"vektor popravaka mjerenja"); EDITMAT(Vv2,"omega=VT*P*V" ); EDITMAT(Ff1,"s0^2=omega/prekobrojnost"); EDITMAT(Ss0,"s0"); EDITMAT(Xx1,"xdef poravljene nepoznate (x0+delta"); EDITMAT(Pm1,"Popravljena mjerenja ldef"); EDITMAT(Kk1,"1.Kontrola treba=~0"); EDITMAT(Kk2,"2.Kontrola treba= omega"); EDITMAT(Kk3,"3.Kontrola treba= popravljenim mjerenjima"); EDITMAT(Cc1,"Cx"); EDITMAT(Sx1,"Sx -srednja greska izracunata"); EDITMAT(Cc2,"Cl - tacnost mjerenja"); EDITMAT(Qq2,"Ql_kapa "); EDITMAT(Qq3,"Qv"); EDITMAT(Cc3,"Cv-Srednje greske popravak sqrt diag"); PRINT("Kontrola K1 =0"+Kk1); IF (K2=V2) THEN PRINT ("Kontrola 2 OK!"); PRINT("Kontrola K2"+Kk2); PRINT("------------------------------"); PRINT("Kontrola K3"+Kk3); END; END;``` Program crashes at Ss0, when viewing matrix via EDITMAT [attachment=10583] [attachment=10584] [attachment=10585] [attachment=10586] ff77=5 gg77=8.6667 EDIT- Some values wern't matrices Code: ```//PROGRAM START LOCAL Nn1,Uu1,Qq1,Dd1,Vv1,Vv2,Kk1,Kk2; LOCAL Kk3,Ff1,Ss0,Xx1,Cc1,Cc2,Cc3,Qq3; LOCAL Qq2,Qq4,Pm1,Sx1; EXPORT function1 () BEGIN LOCAL ff7,gg7; INPUT({ff7,gg7},"Input test", {"Prekobrojnost","Sredina"}); Nn1:=TRN(M1)*M2*M1; Uu1:=TRN(M1)*M2*M3; Qq1:=inv(Nn1); Dd1:=-(Qq1*Uu1); Vv1:=(M1*Dd1)+M3; Vv2:=TRN(Vv1)*M2*Vv1; //K1 - kontrola 1.) popravaka treba biti =0 Kk1:=TRN(M1)*M2*Vv1; //K2 - Kontrola 2.) izjedacenja treba biti = lambdi Kk2:=TRN(M3)*M2*Vv1; Ff1:=Vv2/(ff7); Ss0:=SQRT(Ff1(1,1)); Xx1:=gg7+Dd1; // Popravljena mjerenja su pojedinacna l1,l2,l3...+ matrica V1; Kk3:=M1*Xx1; Pm1:=M4+Vv1; ///Stohasticki dio Cc1:=Ff1(1,1)*Qq1; Sx1:=SQRT(Cc1(1,1)); // Deviacija mjerenja tako sto uzmemo korjen od Cx Cc2:=Ff1(1,1)*inv(M2); //C2 - tacnost mjerenja // srednje greske izvucem iz cl matrice korjen(dijagonalnih) Qq2:=M1*Qq1*TRN(M1); Cc3:=Qq2*Ff1(1,1); ///Srednje greške popravljenih korjen dijagonale clanova C3 Qq3:=inv(M2)-Qq2; Qq4:=Ff1(1,1)*Qq3; /// ISPISI MATRICA EDITMAT(Nn1,"Matrica Normalnih jednacina"); EDITMAT(Uu1,"u=trn(A)*P*w"); EDITMAT(Qq1,"Kofaktorna matrica"); EDITMAT(Dd1,"vektor popravaka nepoznatih"); EDITMAT(Vv1,"vektor popravaka mjerenja"); EDITMAT(Vv2,"omega=VT*P*V" ); EDITMAT(Ff1,"s0^2=omega/prekobrojnost"); //EDITMAT(Ss0,"s0"); //EDITMAT(Xx1,"xdef poravljene nepoznate (x0+delta"); EDITMAT(Pm1,"Popravljena mjerenja ldef"); EDITMAT(Kk1,"1.Kontrola treba=~0"); EDITMAT(Kk2,"2.Kontrola treba= omega"); EDITMAT(Kk3,"3.Kontrola treba= popravljenim mjerenjima"); EDITMAT(Cc1,"Cx"); ///EDITMAT(Sx1,"Sx -srednja greska izracunata"); EDITMAT(Cc2,"Cl - tacnost mjerenja"); EDITMAT(Qq2,"Ql_kapa "); EDITMAT(Qq3,"Qv"); EDITMAT(Cc3,"Cv-Srednje greske popravak sqrt diag"); PRINT("Kontrola K2"+Kk2); PRINT("------------------------------"); PRINT("Kontrola K3"+Kk3); PRINT("S0="+Ss0); PRINT("Xdef. popravljene nepoznate (x0+delta)"+Xx1); PRINT("Sx-srednja greska izracunata"+Sx1); PRINT("Kontrola K1 =0"+Kk1); IF (K2=V2) THEN PRINT ("Kontrola 2 OK!"); END; END;``` Now it works RE: Combine Export and Local variables? - Amer7 - 04-12-2022 07:09 AM I'm again having issues with this variation of program Code: ``` EXPORT function1 () BEGIN LOCAL ff7,gg7; INPUT({ff7,gg7},"Prekobrojnost", {"Unesi prekobrojnost u","Unesi srednju vrijednost xo"}); LOCAL Nn1,Uu1,Qx1,Dd1,Vv1; Nn1:=TRN(M1)*M2*M1; Uu1:=TRN(M1)*M2*M3; Qx1:=inv(Nn1); Dd1:=-(Qx1*Uu1); Vv1:=(M1*Dd1)+M3; LOCAL Om1,Vf1,Ss0,Xx1,Ll1; Om1:=TRN(Vv1)*M2*Vv1; Vf1:=Om1/ff7; Ss0:=CAS("sqrt(Vf1)"); Xx1:=gg7+Dd1; Ll1:=M4+Vv1; LOCAL Kk1,Kk2,Kk3; Kk1:=TRN(M1)*M2*Vv1; Kk2:=TRN(M3)*M2*Vv1; Kk3:=M1*Xx1; ////////STOHASTICKI DIO LOCAL Cx1,Cl1,Ql1,Clk1,Qvk1,Cv1,SCx1; Cx1:=Vf1(1,1)*Qx1; SCx1:=CAS("sqrt(Cx1)"); //////Q= CL Local Cl1d,Cld2; Cl1:=Vf1(1,1)*(inv(M2)); Cl1d:=diag(Cl1); Cld2:=CAS("sqrt(Cld1)"); //Cl=CL kappa LOCAL Cll1,Cll2; Cl1:=Ql1*Vf1(1,1); Cll1:=diag(Cl1); Cll2:=CAS("Sqrt(Cll1)"); //////QL kappa Ql1:=M1*Qx1*TRN(M1); //QV Qvk1:=inv(M2)-Ql1; ///CV LOCAL Ccv1,Ccv2; Cv1:=Qvk1*Vf1(1,1); Ccv1:=diag(Cv1); Ccv2:=CAS("sqrt(Ccv1)"); EDITMAT(Nn1,"N"); EDITMAT(Uu1,"u"); EDITMAT(Qx1,"Qx"); EDITMAT(Dd1,"Delta"); EDITMAT(M5,"v"); EDITMAT(Om1,"Omega"); EDITMAT(Vf1,"vf"); EDITMAT(Ss0,"So"); EDITMAT(Xx1,"X-Popravljene nepoznate"); EDITMAT(Ll1,"Popravljena mjerenja"); EDITMAT(Kk1,"Kontrola 1"); EDITMAT(Kk2,"Kontrola 2"); EDITMAT(Kk3,"Kontrola 3"); //// Stohasticki EDITMAT(Cx1,"Cx"); EDITMAT(SCx1,"Sx - Std."); EDITMAT(Cl1,"Cl"); EDITMAT(Cld2,"Srednje greske iz CL"); EDITMAT(Ql1,"Ql_kapa"); EDITMAT(Cll2,"Srednje greske popravljenih"); EDITMAT(Clk1,"Cl_Kapa"); EDITMAT(Qvk1,"Qv_kapa"); EDITMAT(Cv1,"Cv"); EDITMAT(Ccv2,"Srednje greske popravaka"); PRINT("Vf="+Vf1); END;``` Issue is on line 38 When ever I try to compute Vf1 with an Matrix it starts crashing with (input) problem Vf1= is Vf1:=Om1/ff7; ff7- is user input on start of the program I have tried making sure it's a matrix by M8:=Vf1(1,1); Again it crashes Cl1:=Vf1(1,1)*(inv(M2)); I've tried putting it in CAS("(Om1/ff7"); -Still doesnt work In my Edit mat Vf1 ( has only one element) And M2 is diagonal Matrix (4x4) Is there a way I assign the value of Vf1(1,1) to be a regular number so I could multiply the Matrix M2 without getting an issue? When I try to do I manually like in home: M2(1,1)*inv(M3) - I get correct numbers RE: Combine Export and Local variables? - roadrunner - 04-12-2022 05:18 PM A couple things i noticed: First, I think this line: Cld2:=CAS("sqrt(Cld1)"); Should be this: Cld2:=CAS("sqrt(Cl1d)"); Second, In this line: LOCAL Cx1,Cl1,Ql1,Clk1,Qvk1,Cv1,SCx1; you declare variable Ql1 but I didn't see anywhere that is was assigned a value. It looks like you started to with this: //////Q= CL, but remed it out. When you declare a variable they start out at zero so at this line: Cl1:=Ql1*Vf1(1,1); Cl1 = 0*Vf1(1,1) which is zero. That causes this line: EDITMAT(Cl1,"Cl"); to flag an error. EDITMAT only works on matrix variables. RE: Combine Export and Local variables? - Amer7 - 04-12-2022 06:34 PM (04-12-2022 05:18 PM)roadrunner Wrote:  A couple things i noticed: First, I think this line: Cld2:=CAS("sqrt(Cld1)"); Should be this: Cld2:=CAS("sqrt(Cl1d)"); Second, In this line: LOCAL Cx1,Cl1,Ql1,Clk1,Qvk1,Cv1,SCx1; you declare variable Ql1 but I didn't see anywhere that is was assigned a value. It looks like you started to with this: //////Q= CL, but remed it out. When you declare a variable they start out at zero so at this line: Cl1:=Ql1*Vf1(1,1); Cl1 = 0*Vf1(1,1) which is zero. That causes this line: EDITMAT(Cl1,"Cl"); to flag an error. EDITMAT only works on matrix variables. Wow, I really appreciate for spotting that mistake. Now it works. I really have to find some other program to write in, and I should start more like using names to be easier to spot the mistake. Thank you for your time to spot the mistake!