Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to symbolic differentiate a sum of N unknown variables?

I want to take the derivative of the following function with the variable beta:

\sum_{k=1}^n \frac{\beta X_i \sin\theta_i}{1+\beta^2 X_i}

In maxima, I can do it by:

diff(sum(β*X[i]*sin(θ[i])/(1+β*β*X[i]*X[i]), i, 1, N), β);

How can I do it via sagemath? I have tried the following code:

X = function('X')
theta = function('theta')
var('beta, k, n')
E(beta) = symbolic_sum(beta*sin(theta(k))*X(k)/(1+beta*beta*X(k)*X(k)), k, 1, n)
print(E)
print(simplify(derivative(E, beta)))

But the result is different from the one of maxima:

beta |--> beta*sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)
beta |--> -2*beta^2*n*X(k)^3*sin(theta(k))/(beta^2*X(k)^2 + 1)^2 + sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)

How should I do it correctly?

How to symbolic differentiate a sum of N unknown variables?

I want to take the derivative of the following function with the variable beta:

$$ \sum_{k=1}^n \frac{\beta X_i \sin\theta_i}{1+\beta^2 X_i}

X_i} $$

In maxima, I can do it by:

diff(sum(β*X[i]*sin(θ[i])/(1+β*β*X[i]*X[i]), i, 1, N), β);

How can I do it via sagemath? I have tried the following code:

X = function('X')
theta = function('theta')
var('beta, k, n')
E(beta) = symbolic_sum(beta*sin(theta(k))*X(k)/(1+beta*beta*X(k)*X(k)), k, 1, n)
print(E)
print(simplify(derivative(E, beta)))

But the result is different from the one of maxima:

beta |--> beta*sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)
beta |--> -2*beta^2*n*X(k)^3*sin(theta(k))/(beta^2*X(k)^2 + 1)^2 + sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)

How should I do it correctly?

How to symbolic differentiate a sum of N unknown variables?

I want to take the derivative of the following function with the variable beta:

$$ \sum_{k=1}^n \frac{\beta X_i \sin\theta_i}{1+\beta^2 X_i} $$

In maxima, I can do it by:

diff(sum(β*X[i]*sin(θ[i])/(1+β*β*X[i]*X[i]), i, 1, N), β);

How can I do it via sagemath? I have tried the following code:

X = function('X')
theta = function('theta')
var('beta, k, n')
from sage.calculus.calculus import symbolic_sum
E(beta) = symbolic_sum(beta*sin(theta(k))*X(k)/(1+beta*beta*X(k)*X(k)), k, 1, n)
print(E)
print(simplify(derivative(E, beta)))

But the result is different from the one of maxima:

beta |--> beta*sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)
beta |--> -2*beta^2*n*X(k)^3*sin(theta(k))/(beta^2*X(k)^2 + 1)^2 + sum(X(k)*sin(theta(k))/(beta^2*X(k)^2 + 1), k, 1, n)

How should I do it correctly?