HP Prime Who know how to do that ?



#6

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.


#7

  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;

#8

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.

#9

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.


#10

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.


Forum Jump: