The Museum of HP Calculators

HP Forum Archive 21

 HP Prime and StringsMessage #1 Posted by Han on 19 Sept 2013, 10:45 a.m. Since the HP Prime is able to handle strings, is it possible to take strings and convert them into functions? I know back in the TI-85 there was such a command. Does/will the HP Prime have the ability to ask users to input a function to be used as a symbolic object like equations in the HP48 series? I tried using the INPUT command but it seems to only accept numerical inputs.

 Re: HP Prime and StringsMessage #2 Posted by Eddie W. Shore on 19 Sept 2013, 4:18 p.m.,in response to message #1 by Han What I found to be the most successful is to pass functions as strings as arguments. Example: ```\\ calculate the numerical derivative of f(X) at X = N EXPORT NDER(str1, N) BEGIN X:=N + .000001; D:=EXPR(str1) X:=N - .000001; D:= D - EXPR(str1); D:= D/(.000002); RETURN D; END; EXPR - numerical evaluation of the string with the appropriate variables substituted. ``` f(X) = 3*e^X - 3*X^2. Find f'(1). NDER("3*e^X - 3*X^2",1) returns 2.15484. We could also use strings to store functions into graphing functions or equations. Example: "3*X+4" - > F1 Hope this helps, Eddie

 Re: HP Prime and StringsMessage #3 Posted by Gilles Carpentier on 19 Sept 2013, 4:54 p.m.,in response to message #1 by Han Quote: I tried using the INPUT command but it seems to only accept numerical inputs. INPUT allows all type of argument but you have put the right delimiters: " " [ ] { } etc. be carefull that A..Z variables are only numericals The INPUT command is very powerfull (default value, on line help ...)

 Re: HP Prime and StringsMessage #4 Posted by Han on 19 Sept 2013, 5:00 p.m.,in response to message #3 by Gilles Carpentier Could you give me an example of how to ask the user to enter in a function that can be used as a function? Ideally I would like to have something like: f(x,y)= and have the user enter in a formula that can be used later on.

 Re: HP Prime and StringsMessage #5 Posted by Namir on 20 Sept 2013, 8:45 a.m.,in response to message #3 by Gilles Carpentier Here is an example of a Newton method that uses a string parameter sFx to pass a string image for a function: ```EXPORT Newton(sFx,xguess,toler) BEGIN LOCAL h,f,fp,diff; REPEAT h:=0.001*(ABS(xguess)+1); X:=xguess; f:=EXPR(sFx); X:=xguess+h; fp:=EXPR(sFx); diff:=h*f/(fp-f); xguess:=xguess-diff; UNTIL ABS(diff)

 Re: HP Prime and StringsMessage #6 Posted by Han on 20 Sept 2013, 10:11 a.m.,in response to message #5 by Namir Thank you for sharing your example, Namir. What I was looking for in particular, however, was an example on how to use INPUT in order to get a function. My goal is to create an interactive app, as opposed to a function like yours in which everything is entered at once. My attempt below results in an input-form-like interface (much like the HP48 series) but the default value is 0, and not a formula. EXPORT EXAMPLE() BEGIN INPUT(F,"Graph 3D","f(x,y)=","Enter the function to graph","1/390*(X^3*Y-X*Y^3"); END; If I do enter a new formula "X*Y" or 'X*Y' -- with the quotes -- I get a syntax error. If I take out the quotes, then (as expected), the value of F is whatever X*Y is equal to the moment the program was run. However, this is not what I want, since I cannot evaluate F at different values of X and Y later within my program. Secondly, if such a procedure should work, then presumably F is a string. How would I then convert a string object into a function? Edited: 20 Sept 2013, 10:16 a.m.

 Re: HP Prime and StringsMessage #7 Posted by Han on 20 Sept 2013, 10:18 a.m.,in response to message #3 by Gilles Carpentier Quote: INPUT allows all type of argument but you have put the right delimiters: " " [ ] { } etc. be carefull that A..Z variables are only numericals The INPUT command is very powerfull (default value, on line help ...) To clarify, I was not referring the the arguments of the INPUT command. Instead the INPUT command -- when in use -- seems to only allow the user to enter in numerical values when the program is running.

Go back to the main exhibit hall