Ask Your Question

keko's profile - activity

2024-02-20 19:36:22 +0200 received badge  Popular Question (source)
2024-02-16 18:34:13 +0200 received badge  Famous Question (source)
2024-02-11 19:48:12 +0200 received badge  Notable Question (source)
2024-02-11 19:48:12 +0200 received badge  Popular Question (source)
2023-05-03 16:04:56 +0200 received badge  Notable Question (source)
2023-05-03 16:04:56 +0200 received badge  Popular Question (source)
2023-05-03 16:04:26 +0200 received badge  Popular Question (source)
2023-05-03 16:04:16 +0200 received badge  Popular Question (source)
2023-05-03 16:04:04 +0200 received badge  Popular Question (source)
2022-12-29 16:34:44 +0200 received badge  Notable Question (source)
2022-12-29 15:28:17 +0200 received badge  Popular Question (source)
2022-01-20 11:34:48 +0200 received badge  Nice Question (source)
2022-01-17 14:57:25 +0200 edited question Solve a system of equations for functions

Solve a system of equations for functions If I run the following code: var('r') f = function('f')(r) g = function('g')(

2022-01-17 14:52:45 +0200 edited question Solve a system of equations for functions

Solve functions in a system of equations If I run the following code: var('r') f = function('f')(r) g = function('g')(r

2022-01-17 14:52:25 +0200 edited question Solve a system of equations for functions

Solve functions in a system of equations If I run the following code: var('r') f = function('f')(r) g = function('g')(r

2022-01-17 14:34:17 +0200 asked a question Solve a system of equations for functions

Solve functions in a system of equations If I run the following code: var('r') f = function('f')(r) g = function('g')(r

2021-12-17 14:07:44 +0200 marked best answer Redefine symbolic function even in derivatives

As a simple example, I have the following variables and functions:

r = var('r')
th = var('th', latex_name = '\\theta')

g = function('g')(r, th)

f = g + diff(g,r)

From now on I want to decompose g into g0and g2 as:

g0 = function('g0', latex_name = 'g_0')(r)
g2 = function('g2', latex_name = 'g_2')(r)

g = g0 + cos(th)*g2

If I print f I still get:

$ f = g(r, \theta) + dg(r,\theta)/dr $

So instead, I apply a substitution on g:

f = f.subs(g==g0+cos(th)*g2)

This changes g, but not diff(g,r):

$f = g_0(r) + g_2(r)*\cos(\theta) + dg(r,\theta)/dr$

In order to change also diff(g,r) I have to substitute explicitly the derivative:

f = f.subs(diff(g,r) == diff(g0+cos(th)*g2, r))

My question is the following:

Is there a way I can redefine a function without having to redefine also every single derivative? This way, I would avoid having to write all these substitutions:

diff(g,r)     ==   diff(g0+g2*cos(th), r),
diff(g,r,r)   ==   diff(g0+g2*cos(th), r, r),
diff(g,th)    ==   diff(g0+g2*cos(th), th),
diff(g,th,th) ==   diff(g0+g2*cos(th), th, th),
diff(g,th,r)  ==   diff(g0+g2*cos(th), th, r),
diff(g,r,th)  ==   diff(g0+g2*cos(th), r,  th)
2021-12-17 13:09:40 +0200 edited question Redefine symbolic function even in derivatives

Redefine symbolic function even in derivatives As a simple example, I have the following variables and functions: r = v

2021-12-17 13:03:27 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function in a tensor field As a simple example, I have the following manifold and chart: M =

2021-12-17 12:34:35 +0200 asked a question Redefine symbolic function even in derivatives

Redefine symbolic function even in derivatives As a simple example, I have the following variables and functions: r = v

2021-12-17 11:21:56 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function As a simple example, I have the following manifold and chart: M = Manifold(2, 'M',

2021-12-17 09:59:31 +0200 received badge  Enthusiast
2021-12-16 15:28:48 +0200 commented answer Partial derivative and chain rule

Thanks! Sometimes I struggle to find information about certain topics of SageMath (as the one in this thread), so the to

2021-12-16 15:19:50 +0200 marked best answer Partial derivative and chain rule

I have the following variable and function:

var('r')
g = function('g')(r)

Now, I define the function f, which depends on g:

f = function('f')(g)

If I want to compute the derivative diff(f,r), I get:

D[0](f)(g(r))*diff(g(r), r)

which is the usual chain rule. However, if I want the derivative with respect to g:

diff(f,g)

I get an error:

TypeError: argument symb must be a symbol

Is there a way I can calculate the partial derivative of a function? I would expect a symbolic expression, like

$\displaystyle \frac{\partial f}{\partial g}$

I have seen that in REDUCE there is the package DFPART which accounts for derivatives with respect to generic functions, but I have not found an analogous module in SageMath.

2021-12-15 18:05:58 +0200 received badge  Associate Editor (source)
2021-12-15 18:05:58 +0200 edited question Partial derivative and chain rule

Partial derivative and chain rule I have the following variable and function: var('r') g = function('g')(r) Now, I de

2021-12-15 17:14:19 +0200 edited question Partial derivative and chain rule

Partial derivative and chain rule I have the following variable and function: var('r') g = function('g')(r) Now, I de

2021-12-15 17:08:09 +0200 marked best answer Square root of a fraction

I have the following variable and function:

var('r')
f = function('f')(r)

with an equation given by:

eq = sqrt(-1/(f^2*sin(r)^2))-1/sqrt(-f^2*sin(r)^2)

which, in LaTeX expression, looks like:

\begin{equation} \sqrt{-\frac{1}{f\left(r\right)^{2} \sin\left(r\right)^{2}}} - \frac{1}{\sqrt{-f\left(r\right)^{2} \sin\left(r\right)^{2}}} \end{equation}

In principle, this should be equal to zero. However,

bool(eq==0)

gives me False. I have tried with .simplify_full() and following the suggestion in here, I have used ._sympy_().simplify():

eq = eq._sympy_().simplify()
bool(eq==0)

but I still get False. Am I missing something?

2021-12-15 17:08:05 +0200 answered a question Square root of a fraction

I have realized that my problem here was of mathematical nature rather than computational. I was assuming that $-\frac{

2021-12-15 12:59:18 +0200 asked a question Partial derivative and chain rule

Partial derivative and chain rule I have the following variable and function: var('r') g = function('g')(r) Now, I de

2021-12-09 10:34:32 +0200 edited question Square root of a fraction

Square root of a fraction I have the following variable and function: var('r') f = function('f')(r) with an equation

2021-12-09 10:34:22 +0200 edited question Square root of a fraction

Square root of a fraction I have the following data: var('r') f = function('f')(r) with an equation given by: eq = s

2021-12-09 10:34:02 +0200 edited question Square root of a fraction

Square root of fraction I have the following values: var('r') f = function('f')(r) with an equation given by: eq = s

2021-12-09 10:32:05 +0200 asked a question Square root of a fraction

Square root of fraction I have the following values: var('r') f = function('f')(r) with an equation given by: eq = s

2021-11-29 12:31:02 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function As a simple example, I have the following manifold and chart: M = Manifold(2, 'M',

2021-11-29 12:27:49 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function As a simple example, I have the following manifold and chart: M = Manifold(2, 'M',

2021-11-27 11:33:04 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function As a simple example, I have the following manifold and chart: M = Manifold(2, 'M',

2021-11-27 11:32:27 +0200 edited question Globally redefine symbolic function in a tensor field

Globally redefine symbolic function in a tensor As a simple example, I have the following manifold and chart: M = Manif

2021-11-27 11:01:42 +0200 edited question Globally redefine symbolic function in a tensor field

Redefine symbolic function in a tensor As a simple example, I have the following manifold and chart: M = Manifold(2, 'M

2021-11-27 11:00:42 +0200 edited question Globally redefine symbolic function in a tensor field

Redefine symbolic function in a tensor As a simple example, I have the following manifold and chart: M = Manifold(2, 'M

2021-11-26 09:00:47 +0200 marked best answer Globally redefine symbolic function in a tensor field

As a simple example, I have the following manifold and chart:

M = Manifold(2, 'M', structure='Lorentzian')
X.<t,r> = M.chart(r"t r:(0,+oo)")

with these functions:

h = function('h')(r)
h0 = function('h0')(r)

Now, I define the following tensor:

A = M.tensor_field(0,2)
A[0,0] = h

If I print A, I get:

[h(r)    0]
[   0    0]

as I expected. However, from now on I want h to be:

h = 2*h0

After setting h=2*h0, if I print A[:] I get the same tensor I had before, instead of A[0,0] = 2*h0.

How can I redefine a symbolic function inside a tensor? I have tried with A.subs and A.apply_map, but none of them did the job.

2021-11-23 07:18:36 +0200 edited question Substitute multiplication of sine and cosine for a symbolic function

Substitute multiplication of sine and cosine for a symbolic function I have one variable and two functions: th = var('t