HP Forums
Error: Invalid Input on my program - 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: Error: Invalid Input on my program (/thread-7612.html)

Error: Invalid Input on my program - HumbGruland - 01-17-2017 12:39 AM

Hello, and thanks for answering, I'm new to the forum so please tell me if this is the wrong sub-forum.
I recently got an HP Prime, I can't believe how simple it is programming it, however I encountered a few problems when creating a UI for input.

I made a program based on style 2 of:


The code for my program is:

EXPORT PuntoFijo()
 local n,xact,xnue,fx,err,N,f,f1;
 N:=100; xnue:=1;
 if input(
    "Metodo del punto fijo",
    {"f(X)=", "f(X)=", "Error=", "x0="},
      "Ingrese la funcion rodeada por comillas simples",
      "Ingrese la funcion depsejada rodeada por comillas simples",
      "Ingrese el error maximo",
      "Ingrese la raiz aproximada"
  ) then
    for n from 2 to N+1 do
      if abs(fx)<err then break; end;
Basically the same structure, only modified to implement a different numerical method.
The program passes the check.
The problem arises when the program is running; when I try to input the first algebraic function (between simple quotes), I get the message: "Error: Invalid Input", even if I try to input something as simple as a parabola.
Am I doing something wrong?
Is there something my program is missing?
Thanks for your help.

RE: Error: Invalid Input on my program - StephenG1CMZ - 01-17-2017 02:47 PM

I think that one problem may be that the INPUT syntax has changed since Han wrote that in 2013.

Briefly, where previously one would have
INPUT... varname,
now one should use
Where numbers specifies the type of input, for example
INPUT...{{varname,[3]}} might specify string, or 6 might specify list, or 3,6 would be either.
The number you want is probably (DOM_STRING-1).

Check the INPUT help for the exact syntax.

(But if you are using CAS input, I don't know).

RE: Error: Invalid Input on my program - Han - 01-17-2017 04:14 PM

INPUT() has gone through a number of changes since that post. There are two ways to get around the issue you have:

1) Initialize your f and f1 to objects of the type you wish to use in the INPUT() command. When you do not initialize them, then they are set to the value 0 by default (type: real number). Thus, when a user then enters something that is not a real number, the INPUT() command complains of invalid input. You can, for example, set f:='X^2-5' and f1:='2*X' before the INPUT() command, and then it will expect an algebraic expression.

2) The other method use the more advanced form of INPUT() to enforce the input type for each field (i.e. f and f1 and be required to expect an expression). The help screen for INPUT() explains everything you need to make use of the advanced form.

There is yet another bug in your program, though. You have a line: M0:={}. While technically incorrect (because M0 is a vector/matrix and not a list), the HP Prime will happily convert the empty list into a vector and insert at least a 0 -- the built-in variables may not be "empty" so it auto-fills the first value with 0. The problem, however, is that you are using M0 as a matrix. So you will get yet another error when your program reaches this point. Instead, initialize M0 using: M0:=[[0]]; and your program should be fine (this makes M0 a matrix and not a vector).