Post Reply 
Program help needed
11-22-2014, 06:04 PM
Post: #4
RE: Program help needed
(11-22-2014 03:53 PM)DrD Wrote:  Sorry, Han, I was asking: (in terms of the list variables), "how can I get the program (top post) to produce the same result as grad(x^2-3*x*y^3,{x,y}); does when it's manually entered in the CAS view entry line?" grad(x^2-3*x*y^3,{x,y}); --> [-3*y^3+2*x,-9*x*y^2]

Specifically, the program line: return grad(x^2-3*x*y^3,{x,y}); crashes at run-time due to it's variables being auto-initialized to 0. (It's a CAS command vs. non-CAS program thing.)

Thanks for your help!

I must have mixed up this post with another prior post of yours about commas in vectors. When you say "crash" are you referring to an actual hardware crash? Or did you simply mean that the program returned an error?

Anyway, the issue here is that regular programs are run in Home view, and not CAS view. If you want to do CAS calculations, you are better off creating a CAS program. That said, you can use CAS.function() or CAS("command string"). The thing to watch out for with CAS.function() is that you don't want the arguments for CAS.function() to be pre-parsed as if run from Home view (which is the case for non-CAS programs). So encapsulate the arguments with double quotes.

CAS.grad("x^2-3*x*y^3","{x,y}");

or (if using the other syntax):

CAS("grad(x^2-3*x*y^3, {x,y}");

The first method is good for a single CAS calculation (usually if it's the result you want to return). The second method is better for multiple CAS calculations. For example, if you wanted to use the result and compute the norm of the gradient:

CAS("gr:=grad(x^2-3*x*y^3, {x,y}");
CAS("(gr(1)^2+gr(2)^2)^(1/2)");

This is also how one can do CAS calculations while in Home view. Specifically for your example, you can type (in Home view):

grad("x^2-3*x*y^3", "{x,y}");

and it will work just fine.

Quote:AND thanks also, to Joe for pointing out that unchecking the "Textbook Display" on pg 2 of Home settings, FIXES the lack of "comma separation in the vector" problem! Otherwise the result of the above example would display like: [-3*y^3+2*x -9*x*y^2] and that's just not good!

-Dale-

Have you tried mat2list() as suggested? If you use mat2list(), you won't have to disable the textbook display.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Program help needed - DrD - 11-22-2014, 01:36 PM
RE: Program help needed - Han - 11-22-2014, 01:44 PM
RE: Program help needed - DrD - 11-22-2014, 03:53 PM
RE: Program help needed - Han - 11-22-2014 06:04 PM
RE: Program help needed - DrD - 11-22-2014, 08:34 PM
RE: Program help needed - Han - 11-22-2014, 09:02 PM
RE: Program help needed - DrD - 11-22-2014, 11:29 PM
RE: Program help needed - Han - 11-23-2014, 12:50 AM
RE: Program help needed - DrD - 11-23-2014, 03:25 PM
RE: Program help needed - Han - 11-23-2014, 05:32 PM
RE: Program help needed - DrD - 11-24-2014, 12:07 PM
RE: Program help needed - Han - 11-24-2014, 01:43 PM



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