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, 08 Jan 2022 02:41:57 +0100Implicit Differentiation help?https://ask.sagemath.org/question/60575/implicit-differentiation-help/ How can I prove that dy/dx = x^3 + x is equal to y = x^4/4 + x^2/2 + C using SageMath?
I'm interested in merging SageMath and LaTeX together in some way to help with my note-taking skills for college coming up. Thanks!Rossa625Sat, 08 Jan 2022 02:41:57 +0100https://ask.sagemath.org/question/60575/How to define more complicated differential expressions in Sage?https://ask.sagemath.org/question/24983/how-to-define-more-complicated-differential-expressions-in-sage/ Dear Community,
i have a very hard time doing something pretty straight foreward in Sage. In mechanics, there is a Lagrange-formalism that yields the equation of motion of a system of $n$ degrees of freedom in the following way:
$$
0=\frac{d}{dt}\left(\frac{\partial L}{\partial x'_i(t)}\right) - \frac{\partial L}{\partial x_i(t)}
$$
where $L$ is the Lagrange function
$$
L=E_{Kin} (x'_{1}(t),x'_2(t)...x'_n(t); x_1(t),x_2(t)...x_n(t) ) - E _{Pot}(x_1(t),x_2(t),...,x_n(t))
$$
is the kinetic energy minus the potential energy. The kinetic energy depends on the speeds of the coordinates $x'_i(t)$, while the potential energy depends on the coordinates $x_i(t)$.
In Mathematica, the hack is
L = Ekin[x'[t]] - Epot[x[t]];
eq = 0 == D[D[L, x'[t]], t] - D[L, x[t]];
which gives
0 == Epot'[x[t]] + Ekin''[x'[t]] x''[t]
I can easily specify something for $E_{Kin}$ and $E_{Pot}$, solve the latter equation for $x''$, and give it as a right handside to some time integration scheme.
How can this be done in Sage? Assume you have complicated expressions for $E_{Pot}$ and $E_{Kin}$ which you do not want to differentiate by hand.
`var('L,x,t')`
`x = function('x',t)`
`L = function('L',x,t)`
allows for
`diff(L,t)`
but not
`diff(L,x)`
Thanks already!schneider chenMon, 24 Nov 2014 19:58:57 +0100https://ask.sagemath.org/question/24983/Calculus with formal functions: substitution?https://ask.sagemath.org/question/10928/calculus-with-formal-functions-substitution/If I enter
var('f,x,y')
y = function('y',x)
f = function('f',x,y)
then
f.diff(x)
returns
D[1](f)(x, y(x))*D[0](y)(x) + D[0](f)(x, y(x))
In order to perform more computations later on, I want to rewrite this, using substitutions, so it looks something like
Fy*yx + Fx
But I've got no idea how to do this. In Maxima I'd just use `'diff(f,x)` as the expression to substitute for, but even trying to use `dummy_diff` doesn't seem to work:
from sage.calculus.calculus import dummy_diff
dummy_diff(f,x)
produces the same result as `f.diff(x)` above.
Does anybody know how I can use substitutions to express the results of a formal differentiation with other symbols?AlasdairThu, 16 Jan 2014 08:18:05 +0100https://ask.sagemath.org/question/10928/Implicit differentiation displays extraneous x variable.https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/The problem is, given `y = 9*x^(1/2) - 2*y^(3/5)`, find dy/dx
The answer is supposed to be `dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )`
When I enter the following syntax, there is an extraneous character, (x), displayed:
y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
Is it possible to display the answer without showing (x)?
bxdinSun, 28 Jul 2013 10:34:47 +0200https://ask.sagemath.org/question/10393/problem with numerical integration and differentiation with scipyhttps://ask.sagemath.org/question/9272/problem-with-numerical-integration-and-differentiation-with-scipy/Hi,
I was trying to learn Scipy, using it for integration and differentiation, but at the very initial step I encontered the following problems.
First, the following integration has a complex value as its numerical result when is solved analytically, but the numerical solution only gives its real part without any note for caution:
reset()
forget()
import scipy as sp
from scipy import integrate
var('y')
f=lambda x: 10^10*sin(x)
g=lambda x,y: f(x+y^2)
I=integrate.dblquad(g(x,y), 0, pi, lambda y:0,lambda y:1)[0]; show(I)
show( integral(integral(g(x,y),x,0,1),y,0,pi) )
show( integral(integral(g(x,y),x,0,1),y,0,pi).n() )
is this natural or I am doing something wrong that may cause my even **Real calculations** erratic?
Next, about numerical differentiation, it seems that the only function that works for callable functions is scipy.derivative() if I'm right!? However, I couldn't work with it:
**1st)** when I am not going to specify the point at which the differentiation is to be taken, e.g. when the differentiation is under an integral so that it is the integral that should assign the numerical values to its integrand's variable, not me. As a simple example I tried this code:
import scipy as sp
from scipy import integrate, derivative
I2=integrate.quad( sp.derivative(f(y),y, dx=0.00001, n=1, order=7) , 0, pi,)[0]; show(I2)
show( integral(diff(f(y),y),y,0,1).n() )
also it gives the warning that "Warning: The ocurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated."
**2nd)** when I want to find the derivative of a multivariable function like g(x,y) in the above example, and something like sp.derivative(g(x,y),(x,0.5), dx=0.01, n=1, order=3) gives error as was easily expected.
Looking forward to hearing from you if that integration result is natural and how to resolve the above cited problems with numerical differentiation.
Best RegardsowariTue, 28 Aug 2012 12:15:47 +0200https://ask.sagemath.org/question/9272/