The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime Who know how to do that ?
Message #1 Posted by dg1969 on 22 Oct 2013, 10:18 a.m.

I want to ask for a function f (X) with the command "INPUT" ... then create the function F1 = f(i*X).

example: f(X)=1/(1+0.2*X+5*X^2) => F1(X)=1/(1+0.2*i*X+5*(i*X)^2)

EXPORT test()
BEGIN
  LOCAL f;
  IF INPUT(f,"ENTER f with single quote. Example: '1/X' ") THEN
    F1:=subst(f,X,'(i*X)');
  END;
END;

I try :

F1:=expr("subst(f,'X','(i*X)')");

with another local var g :

g:=subst(f,X,'(i*X)'); F1:=g; or :

CAS("F1:=subst(f,X,'(i*X)')");

I try also with string and the command REPLACE See my previous post...

I do not see it very clear... Thanks for your help.

      
Re: HP Prime Who know how to do that ?
Message #2 Posted by Han on 22 Oct 2013, 12:40 p.m.,
in response to message #1 by dg1969

  LOCAL f;
  IF INPUT(f,"ENTER f with single quote. Example: '1/X' ") THEN
    f:=STRING(f); // not needed this if user inputs f in double quotes
    F1:=EXPR("subst('" + f + "','X','i*X');");
  END;
            
Re: HP Prime Who know how to do that ?
Message #3 Posted by dg1969 on 22 Oct 2013, 3:32 p.m.,
in response to message #2 by Han

Many many thanks Han !!

I owe you the most best thing that ever happened to me today ;o)

I hope that in the near future we can manipulate symbolic expressions from within a program so much easier.

            
Re: HP Prime Who know how to do that ?
Message #4 Posted by dg1969 on 22 Oct 2013, 3:57 p.m.,
in response to message #2 by Han

Unfortunately ... This does not always work ... But for my purpose it should not be annoying...

LOCAL f;
  IF INPUT(f,"ENTER f with single quote. Example: '1/X' ") THEN
    f:=STRING(f); // not needed this if user inputs f in double quotes
    F1:=EXPR("subst('" + f + "','X','(i*X)');");
  END;
I add () around i*X to accept power...

for exact coef in f(X) it works great... Examples: '1/X' or '2/(1+2/10*X+5/10*X^2)'

But for example with :

'0.2/(1+X)' => Crash !!

Is it consistent with the expected operation of "subst" ?

Edited: 22 Oct 2013, 4:01 p.m.

                  
Re: HP Prime Who know how to do that ?
Message #5 Posted by Han on 22 Oct 2013, 5:16 p.m.,
in response to message #4 by dg1969

Quote:
Unfortunately ... This does not always work ... But for my purpose it should not be annoying...
LOCAL f;
  IF INPUT(f,"ENTER f with single quote. Example: '1/X' ") THEN
    f:=STRING(f); // not needed this if user inputs f in double quotes
    F1:=EXPR("subst('" + f + "','X','(i*X)');");
  END;
I add () around i*X to accept power...

for exact coef in f(X) it works great... Examples: '1/X' or '2/(1+2/10*X+5/10*X^2)'

But for example with :

'0.2/(1+X)' => Crash !!

Is it consistent with the expected operation of "subst" ?


Remember that if you are using a CAS command, then by introducing a non-exact value into a CAS calculation, you have implicitly told the calculator to switch into approximate mode. What this means is that 0.2/(1+X) gets evaluated first (using whatever X value you currently have) and _then_ the result is passed to the command subst(). I will have to test when I get home on whether it crashes for me. In the meantime, if you should consider using exact().

F1:=EXPR("subst(exact('" + f + "'),'X','(i*X)');");

More info:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi?read=253620#253620

Edited: 22 Oct 2013, 5:17 p.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall