Differentiating a Sum in MATLAB

sara_87
Messages
748
Reaction score
0

Homework Statement



How do i differentiate a sum in MATLAB?

So for an example, if I have:
y = x^2 + \sum^{n}_{j=1}3x_{j}^4

I want to differentiate it with respect to x.
It should return: 2x + \sum^{n}_{j=1}12x_{j}^3

Homework Equations





The Attempt at a Solution



If I want to differentiate y = x^3+2x, this is what i would do:
>> syms x
>> y = x^3+2*x
>> diff(y,x,1)

this gives:

ans =

3*x^2+2


which is correct but how would i do differentiation if i have a sum?

thank you.
 
Physics news on Phys.org
First of all, your problem is laid out wrong. If you differentiate xi with respect to x, you ought to end up with 0, I think. If your sum consists of x's rather than xi's, then sum x = Nx, and you needn't worry about the sums anymore.

I don't think the Matlab symbolic toolbox is too advanced, but I suppose you could "hack" it, e.g.:
z = sum(repmat(x, 1, 10));

Hope this answers your question.
 
sorry, it should be:

y_n = x_n^2 + \sum^{n}_{j=1}3x_{j}^4+x_n^2

so the derivative is:

y' = 2x_n + \sum^{n}_{j=1}3x_{j}^4+2x_n

What does z = sum(repmat(x, 1, 10)); do?

thank you
 
repmat just makes multiple instances of its input, e.g.
repmat(x, 1, 2) = [x, x]

I'm still a bit unclear as to what you're doing.
If you're differentiating yn with respect to xn, the sum reduces to 12xn^3, i.e.
<br /> y_n&#039; = 2x_n + 12x_n^3 + 2x_n<br />

Do you then sum over the different y'n or what? That way you'd get
<br /> y&#039; = \sum_{i=1}^n y_i&#039;= 2x_n + \sum_{i=1}^n 12x_i^3 + 2x_n<br />

EDIT: This would be the same as taking the divergence, if I'm not mistaken.
 
I want to defferentiate:

y_n = x_n^2 + \sum^{n}_{j=1}(3x_{j}^4+x_n^2)

with respect to xn

I know that this should give:

2x_n + \sum^{n}_{j=1}(3x_{j}^4+2x_n)

but i want to try to get this result using matlab.
 
There are two things I don't understand about this problem. First, when finding the nth root of a number, there should in theory be n solutions. However, the formula produces n+1 roots. Here is how. The first root is simply ##\left(r\right)^{\left(\frac{1}{n}\right)}##. Then you multiply this first root by n additional expressions given by the formula, as you go through k=0,1,...n-1. So you end up with n+1 roots, which cannot be correct. Let me illustrate what I mean. For this...
Back
Top