using diff() in a program
05-08-2016, 09:18 AM (This post was last modified: 05-08-2016 09:49 AM by hpfx.)
Post: #1
 hpfx Junior Member Posts: 28 Joined: Jan 2015
using diff() in a program
Hi,
I made a program that need to derivate a function, I don't understand why it does not work.
when I'm in home, I can type diff(3*X+1) I get the expected result.
But when I do the same in a program, I got error.

I tried all kind of possible syntax to make it work.
here is a simple example :
Code:
EXPORT ABCD() BEGIN '3*X+1'▶F9; PRINT(diff(F9)); END;
as you can see, I use F9 to see if expression is correctly entered,
but I get this : "program(X,0,3)" instead.

is it a bug ???

FW version 10077
05-08-2016, 11:15 AM
Post: #2
 roadrunner Member Posts: 283 Joined: Jun 2015
RE: using diff() in a program
Try these changes:

1. change X to lower case
2. use double quotes for the equation
3. store it in a local variable
4. run diff from the CAS

Code:
EXPORT ABCD()  BEGIN  LOCAL temp;  "3*x+1"▶temp;  PRINT(CAS.diff(temp)); END;

Everything mentioned may not be required, but those are rules I generally follow.

In the articles section Mr. Han has a good post about running CAS functions from a program.

05-08-2016, 01:13 PM
Post: #3
 jrozsas Member Posts: 158 Joined: Nov 2014
RE: using diff() in a program
(05-08-2016 11:15 AM)roadrunner Wrote:  Try these changes:

1. change X to lower case
2. use double quotes for the equation
3. store it in a local variable
4. run diff from the CAS

Code:
EXPORT ABCD()  BEGIN  LOCAL temp;  "3*x+1"▶temp;  PRINT(CAS.diff(temp)); END;

Everything mentioned may not be required, but those are rules I generally follow.

In the articles section Mr. Han has a good post about running CAS functions from a program.

does not work

Leo

05-08-2016, 02:13 PM (This post was last modified: 05-08-2016 02:54 PM by informach.)
Post: #4
 informach Member Posts: 109 Joined: Jul 2015
RE: using diff() in a program
Hi!, hpfx:

Syntax:
diff(Expr,[Var or ListVar])

Description:
Returns, the derivative, of an expression, with respect to, a given variable.

d/dx=(3*x+1)=3

Kind Regards.
informach.

Attached File(s) Thumbnail(s)

05-08-2016, 03:03 PM
Post: #5
 DrD Senior Member Posts: 1,101 Joined: Feb 2014
RE: using diff() in a program
Code:
 EXPORT ABCD() BEGIN   F9:="3*X+1";   RETURN diff(F9,X);  // Returns 3 END;
05-08-2016, 08:47 PM
Post: #6
 hpfx Junior Member Posts: 28 Joined: Jan 2015
RE: using diff() in a program
Thank you,
But I still have an issue,
in fact the expression comes from an input.
in that case, I saw that I must use a very strange INPUT syntax {{var,[2]}} in someone else post.

but when I do that :
Code:
 EXPORT ABCD()  BEGIN  LOCAL a;  INPUT({{a,[2]}});  PRINT(diff(a,X));  END;
I got Error: Bad Argument Type

my a var is supposed to be a string, like F9 in DrD code ?

I don't get the logic here...

Also INPUT builtin help is incomplete and wrong.

syntax : INPUT(var,...) *1st form syntax
and
var -> { var_name, [allowed_type_matrix] ... } *2nd form of var definition.

according this, I should be able to type INPUT({var_name},[types]})
but it gives an error ! I must type INPUT({{var_name, [types]}})

also, help is not complete, where is the list of types ? how can we guess ?
05-08-2016, 09:46 PM (This post was last modified: 05-08-2016 10:06 PM by DrD.)
Post: #7
 DrD Senior Member Posts: 1,101 Joined: Feb 2014
RE: using diff() in a program
Code:
 EXPORT ABCD() BEGIN   LOCAL a;   INPUT({{a,[2]}}); //  You don't need to quote your input, since type [2] is a string var   //F9:="3*X+1";   RETURN diff(EVAL(a),X);  //  You need to EVAL(a). END;

Use: 3*X+1 as input to a ==> returns 3
Post: #8
 roadrunner Member Posts: 283 Joined: Jun 2015
RE: using diff() in a program
(05-08-2016 01:13 PM)jrozsas Wrote:  does not work
That's strange, it works here. What version software are you running? I'm running 8151.

edit: upon further investigation it seems that code will only run on 8151
05-09-2016, 12:14 AM (This post was last modified: 05-09-2016 01:05 PM by informach.)
Post: #9
 informach Member Posts: 109 Joined: Jul 2015
RE: using diff() in a program
Hi!, hpfx:

You can see, this link of (Eddie Shore), for learn, the use, of INPUT ... http://edspi31415.blogspot.com.ar/2014/0...mmand.html
However, it's are some examples and the 6030 version.

Kind Regards.
informach.
05-09-2016, 05:16 AM
Post: #10
 cyrille de brébisson Senior Member Posts: 934 Joined: Dec 2013
RE: using diff() in a program
Hello

>in that case, I saw that I must use a very strange INPUT syntax {{var,[2]}} in someone else post.

INPUT is a home command, and in home, you can not use a variable that has not been defined.
so, INPUT is (normally) unable to let you enter an equation in 'x' if 'x' does not exits.
INPUT takes as first argument a variable and let you request it from the user.
but INPUT can also take 2 or more variables, using {var1,.. varn} syntax.
Furthermore, you can tell INPUT that the variable requested have to follow a given type or types. This is done by placing the variable in a list and having the allowed types as a matrix in the 2nd element of the list.
It is only to make it easier for the system to distinguish between the use of the 3 syntaxes that you are forced, if you want to specify the type for one single variable to still create a list of list...

anyhow, here the 2 means string. So it forces the input to be a string. and strings, contrary to expression can contain anything you want, including the text of undefined variables.

This is why you use {{var [2]}}

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
05-09-2016, 12:52 PM
Post: #11
 jrozsas Member Posts: 158 Joined: Nov 2014
RE: using diff() in a program
(05-08-2016 01:13 PM)jrozsas Wrote:  does not work
That's strange, it works here. What version software are you running? I'm running 8151.

edit: upon further investigation it seems that code will only run on 8151
version 10077

Leo

05-09-2016, 01:05 PM
Post: #12
 roadrunner Member Posts: 283 Joined: Jun 2015
RE: using diff() in a program
Jrozsas,

Cyrille's document explains everything, located here:

Below is a modified program that works with 10077:

Code:
EXPORT ABCD() BEGIN  LOCAL temp;  temp:="3*x^2+1";  CAS.diff(EVAL(temp),"x"); END;

05-10-2016, 09:56 AM
Post: #13
 leprechaun Member Posts: 90 Joined: Mar 2015
RE: using diff() in a program
There are some citations I found very important.

1)
Cas function calls from home, using fully qualified names or not, have all the parameters defined as ‘do not evaluate’.
->This seems to be the main subject to change in the latest update. You need to EVAL() the local variable for the call. Otherwise it is just the name that is used. That is where EVAL() and QUOTE() come in.

2)
This is solved by allowing you to use strings as parameters for the CAS. These strings will be parsed at the time of the CAS function call.
->As usual I would say

3 -(local variables)
These are temporary and local to this specific call of the function.
->Something that personally I was not aware of. My intuition dictated that a local variable would be passed by value, but it seems that a local variable is indeed invisible outside the function.

Please correct me if I am talking nonsense. i don't want to baffle people but sometimes the view of a different person can be enlightening.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)