Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Trouble with defining function from gradiant' topicStudent Support Forum > General > "Trouble with defining function from gradiant"

Next Comment >Help | Reply To Topic
Author Comment/Response
Gandalf Saxe
11/30/11 06:26am

Hi everyone. I've been using basically a whole day on two trivial Mathematica issues, so I'm finally going online for help:


1. Is there any simple way to define the gradient as a new function as such? My try:

Clear["Global`*"]
f[u_] := x[u]*y[u]
gradf[u_] := D[f[u], {{x[u], y[u]}}]
gradf[u]
x[u_] := Exp[u]
y[u] := Cos[u]
gradf[u]

Which gives: "General::ivar: E^u is not a valid variable. >>"

I can kind of see what the problem is, but I don't know how to fix it. It works fine if I define gradf as an expression instead of a function (without the [u_]:), but I'd like it as a function. Any simple solution?


2. See the attachment. On the final line, it doesn't evaluate the function r2[0] properly. I think the problem is how h[u] is defined as h[u_]:= f[x,y], doesn't work apparently. Any suggestions?



Also I'd love any general suggestions on how to do things easier or simpler in the notebook attachement. I'm a total beginner in Mathematica (just came from Maple) so I probably do a some things not the easiest or simplest way. Any feedback would be good


Any help is appreciated.
Thanks

Attachment: Mat1P13a.nb, URL: ,

Subject (listing for 'Trouble with defining function from gradiant')
Author Date Posted
Trouble with defining function from gradiant Gandalf Saxe 11/30/11 06:26am
Re: Trouble with defining function from gradiant Quinn McKinsey 12/01/11 10:13pm
Re: Re: Trouble with defining function from gra... Gandalf Saxe 12/02/11 2:56pm
Re: Re: Trouble with defining function from gra... Gandalf Saxe 12/02/11 8:27pm
Next Comment >Help | Reply To Topic