INPUT CMD partially operating on CAS code - compsystems - 12-03-2016 05:30 PM
The INPUT CMD is a DIALOG BOXES and is partially operating
if the variables are declared as local (coef1_a, coef2_b, coef3_c, coef4_d) do not work.
Commented the LOCAL VARIABLES
PHP Code:
#cas INPUTtest( ) := begin //local coef1_a, coef2_b, coef3_c, coef4_d; //coef1_a := 9; coef2_b := 8; coef3_c := 7; coef4_d := 6;
//local reset_coef1_a, reset_coef2_b, reset_coef3_c, reset_coef4_d; //reset_coef1_a := 3; reset_coef2_b := 2; reset_coef3_c := 1; reset_coef4_d := 0;
local ObjectType_AllAllowed := -1; local ObjectType_Real := 0; local ObjectType_Integer := 1; local ObjectType_String := 2; local ObjectType_Complex := 3; local ObjectType_Matrix := 4; local ObjectType_List := 6; local ObjectType_Function := 8; local ObjectType_Unit := 9; local ObjectType_CAS := 14;
local ok := 1; local cancel := !ok; local keyPress := 0;
local equ, equ1; purge( a, b, c );
print; // Clear Terminal Window print( "Use cursor keys ↑↓ to move the output screen" ); print( "Another key to continue after PAUSE" ); print( "" ); print( "[PAUSE]" ); wait();
print; // Clear Terminal Window again print( "***** Deduction Quadratic Formula *****" ); // Title print( "" );
print( "assume(a>0);" ); assume( a>0 );
equ:= (a*x^2+b*x+c) = 0; print( string( equ ) ); print ( "[PAUSE]" ); wait( );
keyPress := msgbox( equ, true ); //print( "Key press for MSGBOX CMD: " + ifte( keyPress == ok, keyPress + "=[OK/ENTER]", keyPress + "=[ESC]" ) ); wait( );// 0 for [CANCEL], 1 for [OK/ENTER] if keyPress == ok then
print( "Ans*4*a" ); equ := equ * 4*a; // ((a*x^2+b*x+c)*4*a) = 0 print( string( equ ) ); print( "" ); print( "expand(Ans)" ); equ := expand( equ ); // (4*a^2*x^2+4*a*b*x+4*a*c) = 0 print( string( equ ) ); print( "" );
print( "Ans+b^2" ); equ := equ + b^2; // (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2) print( string( equ ) ); print( "" );
print( "Ans-4*a*c" ); equ := equ - 4*a*c; // (4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2) print( string( equ ) ); print( "" );
print( "factor(Ans)" ); equ := factor( equ ); // (2*a*x+b)^2) = (-4*a*c+b^2) print( string( equ ) ); print( "" );
print( "√(Ans)" ); assume( b>0 ); assume( c>0 ); equ := √( equ ); // (abs(2*a*x+b)) = (√(-4*a*c+b^2)) print( string( equ ) ); print( "" );
equ := expr( replace( string( equ ), "abs", "" ) ); // (2*a*x+b) = (√(-4*a*c+b^2)) print( string( equ ) ); print( "" );
print( "Ans-b" ); equ := equ - b; // (2*a*x+b-b) = (√(-4*a*c+b^2)-b) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // (2*a*x-b) = (√(-4*a*c+b^2)-2*b) print( string( equ ) ); print( "" );
print( "Ans/(2*a)" ); equ := equ / ( 2*a ); // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // x1 = (-b+√(-4*a*c+b^2))/(2*a) equ := expr( replace( string( equ ), "x", "x1" ) ); print( string( equ ) ); print( "" );
print( "expr(replace(string(equ),"-b+","-b-"))" ); equ1 := expr( replace( string( equ ), "-b+", "-b-" ) ); // x2 = (-b-√[b^2-4*a*c])/(2*a) equ1 := expr( replace( string( equ1 ), "x1", "x2" ) ); print( string( equ1 ) );
print( "[PAUSE]" ); wait( );
//keyPress := 1; keyPress := input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ? ax²+bx=d", {"a:", "b:", "c:", "d:"}, {"Enter coeff a", "Enter coeff b", "Enter coeff c", "Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ; if keyPress == ok then a := 1; b := 2; c := 3; //a := coef1_a; //b := coef2_b; //coef3_c := coef3_c-coef3_d; // => ax²+bx+c=0 //c := coef3_c; return([ eval(equ), eval(equ1) ]); end; end;
return "done"; end; #end
INPUTtest(); [enter] open the INPUT DialogBox, but then [enter] returns "Error: Bad argument type" Why?
Now without comment do not execute anything
PHP Code:
#cas INPUTtest():= begin local coef1_a, coef2_b, coef3_c, coef4_d; coef1_a:=9; coef2_b:=8; coef3_c:=7; coef4_d:=6;
local reset_coef1_a, reset_coef2_b, reset_coef3_c, reset_coef4_d; reset_coef1_a:=3; reset_coef2_b:=2; reset_coef3_c:=1; reset_coef4_d:=0;
local ObjectType_Real := 0;
input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ∨ ax²+bx=d", {"a:", "b:", "c:", "d:"}, {"Enter coeff a", "Enter coeff b", "Enter coeff c", "Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ; //... return "done"; end; #end
INPUTtest(); [enter] INPUTtest() ?
RE: INPUT CMD on CAS code - Han - 12-04-2016 04:13 AM
You are creating a CAS program. INPUT() is not a CAS command.
RE: - compsystems - 12-04-2016 02:09 PM
(12-04-2016 04:13 AM)Han Wrote: You are creating a CAS program. INPUT() is not a CAS command.
sorry for my bad English
CHOOSE, MSGBOX cmds are also DIALOG BOXES and works perfectly on CAS MODE, please run the following program.
I think it is a problem with the LOCALS VARIABLES.
Some hp-prime developer that confirms what happens
Thanks
With the current firmware I still can not execute the following code correctly =(
1: Screen does not autoscroll
2: INPUT does not work
3: ASSUME does not work
4: There is not pretty print
5: print; // Clear Terminal Window, does not operate when called for the second time
6: CHOOSE and MSGBOX must be above the terminal window (pop-up) and not go to the CAS/HOME MODE view
7: When copying then paste this source code into the program editor (hp-conn Kit), Tabulation is lost in certain parts.
8: When changing the font size distorts the strings, there must be a flag to set the font size
Any hope of seeing any of the previous points implemented?
Program: Deduction Quadratic Formula Step by Step
PHP Code:
#cas deductionQuadFormula_SbyS( ) := begin //local coef1_a, coef2_b, coef3_c, coef4_d; //coef1_a := 9; coef2_b := 8; coef3_c := 7; coef4_d := 6;
//local reset_coef1_a, reset_coef2_b, reset_coef3_c, reset_coef4_d; //reset_coef1_a := 3; reset_coef2_b := 2; reset_coef3_c := 1; reset_coef4_d := 0;
local ObjectType_AllAllowed := -1; local ObjectType_Real := 0; local ObjectType_Integer := 1; local ObjectType_String := 2; local ObjectType_Complex := 3; local ObjectType_Matrix := 4; local ObjectType_List := 6; local ObjectType_Function := 8; local ObjectType_Unit := 9; local ObjectType_CAS := 14;
local ok := 1; local cancel := !ok; local keyPress := 0;
local equ, equ1; purge( a, b, c );
print; // Clear Terminal Window print( "Use cursor keys ↑↓ to move the output screen" ); print( "Another key to continue after PAUSE" ); print( "" ); print( "[PAUSE]" ); wait();
print; // Clear Terminal Window again print( "***** Deduction Quadratic Formula *****" ); // Title print( "" );
print( "assume(a>0);" ); assume( a>0 );
equ:= (a*x^2+b*x+c) = 0; print( string( equ ) ); print ( "[PAUSE]" ); wait( );
keyPress := msgbox( equ, true ); //print( "Key press for MSGBOX CMD: " + ifte( keyPress == ok, keyPress + "=[OK/ENTER]", keyPress + "=[ESC]" ) ); wait( );// 0 for [CANCEL], 1 for [OK/ENTER] if keyPress == ok then
print( "Ans*4*a" ); equ := equ * 4*a; // ((a*x^2+b*x+c)*4*a) = 0 print( string( equ ) ); print( "" ); print( "expand(Ans)" ); equ := expand( equ ); // (4*a^2*x^2+4*a*b*x+4*a*c) = 0 print( string( equ ) ); print( "" );
print( "Ans+b^2" ); equ := equ + b^2; // (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2) print( string( equ ) ); print( "" );
print( "Ans-4*a*c" ); equ := equ - 4*a*c; // (4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2) print( string( equ ) ); print( "" );
print( "factor(Ans)" ); equ := factor( equ ); // (2*a*x+b)^2) = (-4*a*c+b^2) print( string( equ ) ); print( "" );
print( "√(Ans)" ); assume( b>0 ); assume( c>0 ); equ := √( equ ); // (abs(2*a*x+b)) = (√(-4*a*c+b^2)) // Should not show ABS print( string( equ ) ); print( "" );
// patch equ := expr( replace( string( equ ), "abs", "" ) ); // (2*a*x+b) = (√(-4*a*c+b^2)) print( string( equ ) ); print( "" );
print( "Ans-b" ); equ := equ - b; // (2*a*x+b-b) = (√(-4*a*c+b^2)-b) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // (2*a*x-b) = (√(-4*a*c+b^2)-2*b) print( string( equ ) ); print( "" );
print( "Ans/(2*a)" ); equ := equ / ( 2*a ); // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a) print( string( equ ) ); print( "" );
print( "simplify(Ans)" ); equ := simplify( equ ); // x1 = (-b+√(-4*a*c+b^2))/(2*a) equ := expr( replace( string( equ ), "x", "x1" ) ); print( string( equ ) ); print( "" );
print( "expr(replace(string(equ),"-b+","-b-"))" ); equ1 := expr( replace( string( equ ), "-b+", "-b-" ) ); // x2 = (-b-√[b^2-4*a*c])/(2*a) equ1 := expr( replace( string( equ1 ), "x1", "x2" ) ); print( string( equ1 ) );
print( "[PAUSE]" ); wait( );
//keyPress := 1; keyPress := input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ? ax²+bx=d", {"a:", "b:", "c:", "d:"}, {"Enter coeff a", "Enter coeff b", "Enter coeff c", "Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ; if keyPress == ok then a := 1; b := 2; c := 3; //a := coef1_a; //b := coef2_b; //coef3_c := coef3_c-coef3_d; // => ax²+bx+c=0 //c := coef3_c; return([ eval(equ), eval(equ1) ]); end; end;
return "done"; end; #end
RE: INPUT CMD on CAS code - DrD - 12-04-2016 03:12 PM
Hi Compsystems!
Han mentioned that INPUT() is not a CAS command, and doesn't work inside your CAS program. Han did not specify anything about the CHOOSE() command. Han has offered you good advice.
Whether or not commands work in both environments is not well documented. In general, lowercase commands work in CAS, and probably work in HOME. Uppercase commands work in HOME and may not work in CAS. As the prime evolves, these distinctions are being improved. Case matters, for both commands and variables. If you see issues, errors, etc., you might be more productive if you look at the active environment, and the case of the command name, or variables being used.
-Dale-
RE: INPUT CMD partially operating on CAS code - compsystems - 12-04-2016 03:31 PM
Actually INPUT does work on CAS (partially), after entering the data this fails.
Please try the code above yourself.
Finally, please the HP-Prime team should be to solve the 8 previous points.
I want to create programs that show in a window (terminal window) the output data, request data by dialog boxes and return to show data again. This capability is available on ti68k calcs, or similar to the library I'm writing for the hp50,
see http://www.hpmuseum.org/forum/thread-7048.html
another aption is to create my own TERMINAL VIEW, but I make missing commands (HP50) like convert from string to graphic object (2 -> GROB), etc.
RE: INPUT CMD partially operating on CAS code - DrD - 12-04-2016 04:55 PM
(12-04-2016 03:31 PM)compsystems Wrote: Actually INPUT does work on CAS (partially), after entering the data this fails.
Please try the code above yourself.
This CAS test example demonstrates that the input() command doesn't work in CAS, while the same INPUT() structure does work in the following HOME example:
(Please try the code below for yourself.)
Code:
#cas
CAStest():=
begin
local a,b,c,resetVAL,initVAL;
input ({ {a, [0], {21,21,0}},
{b, [0], {21,21,1}},
{c, [0], {21,21,2}} },
"title",
{"label_a", "label_b","label_c"},
{"help_a", "help_b", "help_c"},
{resetVAL,resetVAL,resetVAL},
{initVAL, initVAL, initVAL} );
end;
#end
Code:
EXPORT HOMEtest()
BEGIN
LOCAL a,b,c,resetVAL,initVAL;
INPUT ({ {a, [0], {21,21,0}},
{b, [0], {21,21,1}},
{c, [0], {21,21,2}} },
"title",
{"label_a", "label_b","label_c"},
{"help_a", "help_b", "help_c"},
{resetVAL,resetVAL,resetVAL},
{initVAL, initVAL, initVAL} );
END;
"Partially" working simply means it doesn't work.
|