Post Reply 
CAS grad() function
05-24-2017, 08:20 PM
Post: #1
CAS grad() function
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 []?
Find all posts by this user
Quote this message in a reply
05-25-2017, 01:02 AM
Post: #2
RE: CAS grad() function
(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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
05-25-2017, 03:09 PM
Post: #3
RE: CAS grad() function
"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.
Find all posts by this user
Quote this message in a reply
05-25-2017, 08:21 PM (This post was last modified: 05-25-2017 08:22 PM by Han.)
Post: #4
RE: CAS grad() function
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
05-25-2017, 08:35 PM
Post: #5
RE: CAS grad() function
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
05-25-2017, 09:55 PM
Post: #6
RE: CAS grad() function
Ah, thanks. I was fooled because the example has the []. and the description says "with" making it sound optional.
Find all posts by this user
Quote this message in a reply
Post Reply 




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