HP Forums
CAS grad() function - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: CAS grad() function (/thread-8394.html)



CAS grad() function - KeithB - 05-24-2017 08:20 PM

How does this work without the variable list? The example gives a "Bad Argument Value" when I delete [x y z].

Shouldn't it produce a unit vector that goes in a particular direction? How do I supply values?

And what the heck is the little +/- that appears when you hit []?


RE: CAS grad() function - Han - 05-25-2017 01:02 AM

(05-24-2017 08:20 PM)KeithB Wrote:  How does this work without the variable list? The example gives a "Bad Argument Value" when I delete [x y z].

Shouldn't it produce a unit vector that goes in a particular direction? How do I supply values?

And what the heck is the little +/- that appears when you hit []?

grad() is a CAS command, so make sure that you are in CAS view. As an example:

grad(x^2*y,[x,y]); //--> [ 2*x*y, x^2]

It does not return a unit vector; it returns the gradient, which is defined as

\[ [ f_{x_1}, f_{x_2} , \dotsm, f_{x_n} ] \]

where \( f \) is a function of the variables \( x_1 \) through \( x_n \), and \( f_{x_i} \) denotes the partial derivative of \( f \) with respect to \( x_i \).

The +/- just means you can add row/columns by editing that position. If you place the cursor on the +/- and press + or - you can add/remove that particular row or column.


RE: CAS grad() function - KeithB - 05-25-2017 03:09 PM

"Returns the gradient of an expression. With a list of variables as second argument, returns the vector of partial derivatives."

That returns the partials. When you delete the list of variables you just get an error "Bad argument values", and no gradient which should be something where all the variables are a dimension. I think the option is so you can have variable constants, as it were.


RE: CAS grad() function - Han - 05-25-2017 08:21 PM

Arguments that are optional are shown with []'s surrounding the argument. As an example, look at the arguments for the input() command. The help for grad() does not show any arguments surrounded by []'s. So I took that to mean that the list of variables is required. By specifying all variables (in the list), then one obtains the gradient (which is basically a list of all partial derivatives). On the other hand, specifying only a (proper) subset of all the variables then one obtains a list of partial derivatives. This was how I interpreted the help text.


RE: CAS grad() function - Han - 05-25-2017 08:35 PM

You can write a short CAS program that will automatically generate the list of variables:

Code:
#cas
gradient(f):=
BEGIN
  return(grad(f,lvar(f)));
END;
#end

Usage: gradient(expression)

This snippet of code, however, is not fool proof. It assumes that all variables in the expression are in fact undefined variables.


RE: CAS grad() function - KeithB - 05-25-2017 09:55 PM

Ah, thanks. I was fooled because the example has the []. and the description says "with" making it sound optional.