ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 30 May 2015 14:15:05 +0200A simple problem related to symbolic calculationhttps://ask.sagemath.org/question/26982/a-simple-problem-related-to-symbolic-calculation/Could anyone let me know how you can define a variable as some function of another variable without specific definition? For example, how can you define theta as some function of x and then differentiate the 'sin(theta)' by x?
The following is my code that doesn't work. I couldn't find how to fix it in reference manuals. Any help will be appreciated.
var('theta, y, f')
y=sin(theta) ; theta=f(x);
y.derivative(x)Nownuri1Sat, 30 May 2015 14:15:05 +0200https://ask.sagemath.org/question/26982/derivative of multivariate equation with nested sumhttps://ask.sagemath.org/question/10869/derivative-of-multivariate-equation-with-nested-sum/Hello,
I often have to deal with functions like the one below, take derivatives and
so on. I would really like to know if I could use a CAS like SAGE to do this tedious and error prone calculations but I couldn't find a similar kind of function in the docs and tutorials.
My questions are:
* how can I write this function in SAGE ?
for $x\in \mathbf{R}^p; v \in \mathbf{R}^{p \times k}$
$$y(x, v) := \sum^p_{i=1} \sum^p_{j>i} \sum_{f=1}^k v_{i,f} v_{j,f} x_i x_j =
\sum^p_{i=1} \sum^p_{j>i} \langle v_{:,i}, v_{;,j} \rangle x_i x_j$$
* calculate the partial derivatives $\frac{\partial y(x,v)}{\partial v_{i,j}}$ ?
* or the the derivative with respect to the column-vector $\frac{\partial y(x,v)}{\partial v_{:, i} }$ ?
Or is there a better way to work with this kind of function in SAGE? (the function above is only an example)
ThanksibayerMon, 30 Dec 2013 13:36:27 +0100https://ask.sagemath.org/question/10869/lagranian mechanicshttps://ask.sagemath.org/question/7856/lagranian-mechanics/I'm working on using sage to help with the Euler-Lagrange equation in my mechanics class. I have this worked up so far for a simple pendulum.
var('m,l,g,th,thdot,thdotdot,t')
th = function('th',t)
thdot = th.diff(t)
thdotdot = thdot.diff(t)
L = 1/2*m*l^2*thdot^2 - m*g*l*(1-cos(th))
diff(L,thdot)
but that gives off the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_23.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dmFyKCdtLGwsZyx0aCx0aGRvdCx0aGRvdGRvdCx0JykKdGggPSBmdW5jdGlvbigndGgnLHQpCnRoZG90ID0gdGguZGlmZih0KQp0aGRvdGRvdCA9IHRoZG90LmRpZmYodCkKTCA9IDEvMiptKmxeMip0aGRvdF4yIC0gbSpnKmwqKDEtY29zKHRoKSkKZGlmZihMLHRoZG90KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpTPoOKC/___code___.py", line 8, in <module>
exec compile(u'diff(L,thdot)
File "", line 1, in <module>
File "/home/eric/sage/local/lib/python2.6/site-packages/sage/calculus/functional.py", line 130, in derivative
return f.derivative(*args, **kwds)
File "expression.pyx", line 2502, in sage.symbolic.expression.Expression.derivative (sage/symbolic/expression.cpp:11917)
File "derivative.pyx", line 216, in sage.misc.derivative.multi_derivative (sage/misc/derivative.c:2191)
File "expression.pyx", line 2570, in sage.symbolic.expression.Expression._derivative (sage/symbolic/expression.cpp:12263)
TypeError: argument symb must be a symbol
I don't have any idea what all this means other than I'm guessing it doesn't like that I am trying to take the derivative with respect to a function?
Any help would be appreciated.ehremingtonSat, 08 Jan 2011 17:02:19 +0100https://ask.sagemath.org/question/7856/Numerical integration in a functionhttps://ask.sagemath.org/question/7660/numerical-integration-in-a-function/ f(x,y)=numerical_integral(1/d*2*x*y,.01,Infinity)[0]
Error
So what I want is to the integration wait until after the variables have been substituted so that it is able to numerically integrate. (Yes I need to numerically integrate. This is a simplified form that reproduces the same result.)
f(3,1)=numerical_integral(1/d*2*3*1,.01,Infinity)[0]
406.69135669845798
I thought there might be a way using a lambda defined function, but I was unable to find one.willmwadeWed, 01 Sep 2010 09:20:26 +0200https://ask.sagemath.org/question/7660/