# HP Forums

Full Version: Error: Invalid Input on my program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:
Code:
``` EXPORT PuntoFijo() BEGIN  local n,xact,xnue,fx,err,N,f,f1;  N:=100; xnue:=1;  if input(     {f,f1,err,xact},     "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"     },     {f,f1,err,xact}   ) then     F1:=f;     F2:=f1;     M0:={};      M0(n,1):=n;     M0(n,2):=xact;     M0(n,3):=F2(xact);     M0(n,4):=abs(F1(xact));     for n from 2 to N+1 do       xact:=xnue;       xnue:=F2(xact);       fx:=F1(xact);       M0(n,1):=n;       M0(n,2):=xact;       M0(n,3):=xnue;       M0(n,4):=fx;       if abs(fx)<err then break; end;     end;     editMat(M0);   end; 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?
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
IINPUT...{{varname,[numbers]}}
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).
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).
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :