INPUT CMD partially operating on CAS code
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() ?
|