[HP-Prime xCAS] My first program



#8

What generates an error when calculating the sum of polynomials?

Quote:
EXPORT PolynomialsTools()
// Syntax: ()
// Command Info: Polynomials Tools
// Author: CompSystems
// Version: 0.07 Sep 5 2013
BEGIN

Local RedColor := { 255, 0, 0 }; // Declara y define los valores del RED Color
Local RedBlack := { 0, 0, 0 }; // Declara y define los valores del Black Color
Local RedWhite := { 255, 255, 255 }; // Declara y define los valores del WhiteColor
Local Font_12 := 2; // Fuente de texto de alto
Local Font_14 := 3;
Local Font_16 := 4;
Local mult:=18; // multiplicador para aumentar a la siguiente linea de texto

Local polyCoef1, polyCoef2, operPCoeff1_2, operType, ChooseOut1, InputOut1, InputOut2, ExprAsStr; // Declara variables locales

Rect_p(); // Limpia la ventana de graficos usada como salida del programa
FREEZE(); // Congela la ventana de graficos
RECT_P( 1, 1, 318, 238, RGB( 0, 0, 0 ), RGB( 255, 255, 255 ) ); // Dibuja un rectangulo de fondo
RECT_P( 1, 1, 318, 16, RGB( 0, 0, 0 ), RGB( 0, 0, 0 ) ); // Dibuja un rectangulo para el titulo

//LOCAL COO1:= { 0, 0 }, COO2:= { 319, 239 }; // Definicion de coordenadas
//RECT_P( { 0, 0 } , { 319, 239 } , RGB( WhiteColor ), RGB( RedColor ); // no acepta lista de coordenadas =(
//RECT_P( COO1 , COO2 , RGB( WhiteColor ), RGB( RedColor ); // ni llamar a un avarible como coordenada =(

TEXTOUT_P( "PolynomialsTools", 3, 3, Font_12, RGB( 0,148,255 ) );
wait(2);


// ChooseOut1: = Choose( operType, "Choose Operation", { { " Addition", "+" } , { " Difference", "-" }, { " Mul", "*" } , { " Div", "/" } } ); // sentencia aun no soportada =(
// If ChooseOut1 == true ... // sirve para reutilizar el valor de ChooseOut1 mas abajo
// Then
// WAIT(); // para visualizar la entrada en el campo superior
// Else kill;
// End; //If

If
Choose( operType, "Choose Operation", { { " Addition", "+" } , { " Difference", "-" }, { " Mul", "*" } , { " Div", "/" } } )
Then
Case // Como choose actualmente no admite listas con varios parametros tengo que hacer un selector para llevar el # a una opcion =(
If operType == 1
Then
operType := "+";
End;
If operType == 2
Then
operType := "-";
End;
If operType == 3
Then
operType := "*";
End;
If operType == 4
Then
operType := "/";
End;
// Default
End;
End;//If

// Asigna a las variables anteriores por una caja de dialogo

InputOut1:= Input( polyCoef1, "Polynomials Tools", "PolyCoef1 = ", "Input coeffs of a poly1 c1*x^n + c2*x^n-1 +...+ c3*x + c4" );
If InputOut1 == true
Then
WAIT(); // para visualizar la entrada en el campo superior
Else kill;
End; //If


InputOut2 := Input( polyCoef2, "Polynomials Tools", "PolyCoef2 = ", "Input coeffs of a poly2 c1*x^n + c2*x^n-1 +...+ c3*x + c4" );
If InputOut2 == true
Then
WAIT(); // para visualizar la entrada en el campo superior
Else kill;
End; //If

Rect_p(); // Limpia la ventana de graficos usada como salida del programa
FREEZE(); // Congela la ventana de graficos

// Redibuja la ventana por que comando CHOOSE se sale de la actual, espero que HP solucione esto en la proxima version
RECT_P( 1, 1, 318, 238, RGB( 0, 0, 0 ), RGB( 255, 255, 255 ) ); // Dibuja un rectangulo de fondo
RECT_P( 1, 1, 318, 16, RGB( 0, 0, 0 ), RGB( 0, 0, 0 ) ); // Dibuja un rectangulo para el titulo
TEXTOUT_P( "PolynomialsTools", 3, 3, Font_12, RGB( 0,148,255 ) );

If operType == "/"
Then
ExprAsStr:= "polyCoef1 " + "," + " polyCoef2";
//operPCoeff1_2 := expr( propfrac(ExprAsStr) ) ; // calcula la operacion
operPCoeff1_2 := "expr( propfrac(" + ExprAsStr + ")" ; // calcula la operacion
TEXTOUT_P( "polyCoef1 " + operType + " polyCoef2: " , 3, mult, Font_14, RGB( 0, 0, 0 ) ); // Despliega la operacion calculada entre los polinomios
Else
ExprAsStr:= "polyCoef1 " + operType + " polyCoef2 ";
operPCoeff1_2 := expr( ExprAsStr ) ; // calcula la operacion
TEXTOUT_P( ExprAsStr + ": " , 3, mult, Font_14, RGB( 0, 0, 0 ) ); // Despliega la operacion calculada entre los polinomios
End;//If

TEXTOUT_P( polyCoef1 + " " + operType + " " + polyCoef2 + " = " + operPCoeff1_2, 3, mult*2, Font_16, RGB( 0, 0, 0 ) ); // Despliega el valor de la operacion de los polinomios, forma de coeficientes

// la siguiente sentencia falla en la version actual del emulador 2013/8/13 =(
TEXTOUT_P( "poly2Symb(polyCoef1)" + " " + operType + " " + "poly2Symb(polyCoef2)" + " = " + operPCoeff1_2, 3, mult*3, Font_16, RGB( 0, 0, 0 ) ); // Despliega el valor de la operacion de los polinomios, forma de expresion math

//CAS; // or // CAS(); // retorna a la pantalla o ventana CAS

// ejemplos

// (x^2+3)+(x) => x^2+x+3 // como expresion algebraica
// [ 1, 0, 3 ] + [ 1, 0 ] => [ 1, 1, 3 ]

// (x^2+3)/(x) => x+(3/x) // como expresion algebraica
// [ 1, 0, 3 ] / [ 1, 0 ] => { [1,0], 3/[1,0] }


END;


http://www.adictoshp.org/topic/413-hp-prime-xcas-my-first-program/

Edited: 5 Sept 2013, 1:06 p.m. after one or more responses were posted


#9

Nice program. Sorry it is not working.

Can you tell me if the HP connectivity kit for prime is available so we can duplicate your program? It looks easier to use than the emulator for programming.


Thank you,

PG


#10

Using the emulator you can enter programs from source text files using the following steps:

1. Type in the program in your favorite text edit. You can also copy a program from another source. I recommend that you paste it in your favorite text editor to detect ad remove control and extended ASCII character.

2. Copy the text in your editor.

3. Using the HP emulator, create a program with the same name.

4. Edit the program and delete all that the emulator has created.

5. Use the edit | Paste command to paste the source code.

6. Click the Check button to make sure that the program you pasted has no errors detectable by the emulator.

7. Correct any errors that are flagged.

8 Exit the emulator's editor.

9. Run the program

#11

Yup, the connectivity kit (HP_Connectivity_Kit.zip) is available from the same location as the firmware upgrades, a location which was previously leaked to this forum :)

#12

updated to version 0.03 =)


#13

updated to version 0.07 =)


#14

A small OT: i don't analyze your request/bug report on this forum but your reports seems "serious", so i feel that i should acknowledge your commitment to the hp prime.


Possibly Related Threads...
Thread Author Replies Views Last Post
  Sending little images to the Prime (...and Program name bug?) Erwin Ried 19 2,933 12-10-2013, 05:35 PM
Last Post: Erwin Ried
  Problem with debug HP prime program, somebody help me? Carlos CM (Mexico) 6 1,405 12-05-2013, 03:07 PM
Last Post: Carlos CM (Mexico)
  HP PRIME: APP program code DISAPPEARS !! Joseph Ec 0 442 11-25-2013, 11:35 AM
Last Post: Joseph Ec
  Prime: Placing more than 1 item on the RPN stack in a single program? John Colvin 4 921 11-19-2013, 08:59 AM
Last Post: Miguel Toro
  Prime: Program size limited to 64K? Erwin Ried 4 855 11-17-2013, 11:42 PM
Last Post: Joseph Ec
  [HP-Prime] Picking elements from a List in a program Jean-Michel 3 809 11-15-2013, 04:16 AM
Last Post: dg1969
  HP Prime: Recommendation for future RPN Program Mode BruceTTT 3 841 11-13-2013, 10:03 PM
Last Post: BruceTTT
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 1,102 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  [prime] Insert a breakpoint in a program for debugging ? Olivier Lecluse 3 738 11-09-2013, 09:41 PM
Last Post: Joseph Ec
  HP PRIME: Hide return value from program and swap Edit with Run vrrr 2 730 11-09-2013, 04:04 PM
Last Post: vrrr

Forum Jump: