Jim Clark wrote:
> The reference manual shows the following example for the gradient()  
> function:
> 
> sage: x,y = var('x y')
> sage: f = x^2+y^2
> sage: f.gradient()
> (2*x, 2*y)
> 
> However, if instead I enter:
> 
> sage: x,y,n = var('x y n')
> sage: f = x^n+y^n
> sage: f.gradient()
> (y^n*log(y) + x^n*log(x), n*x^(n - 1), n*y^(n - 1))
> 
> (not what I wanted, but I can understand what happened.)
> So I tried:
> 
> sage: f(x,y) = x^n+y^n
> sage: f.gradient()
> ((x, y) |--> y^n*log(y) + x^n*log(x), (x, y) |--> n*x^(n - 1), (x, y)  
> |--> n*y^(n - 1))
> 
> So even if I specify that f is a function of x and y,
> gradient() still insists on also differentiating w.r.t. n
> 
> How do I tell gradient() that n is a constant?


Good point.  Right now, the gradient function looks like this:

         from sage.modules.free_module_element import vector
         l=[self.derivative(x) for x in self.variables()]
         return vector(l)

That second line should probably be
         l=[self.derivative(x) for x in self.arguments()]

and then your last example should work.

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to