Differentiating a Sum in MATLAB

Click For Summary

Homework Help Overview

The discussion revolves around differentiating a mathematical expression involving a sum in MATLAB. The original poster presents a function that includes both a polynomial term and a summation, seeking guidance on how to perform differentiation with respect to a variable.

Discussion Character

  • Exploratory, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants explore the differentiation of a sum and question how to handle terms involving multiple variables. There is discussion about the implications of differentiating terms that include sums and whether certain variables should be treated as constants or functions of another variable.

Discussion Status

Some participants have provided insights into MATLAB's capabilities and suggested alternative approaches, while others have raised questions about the setup of the problem and the implications of differentiating certain terms. The conversation is ongoing, with various interpretations being explored.

Contextual Notes

There are indications of confusion regarding the treatment of variables in the summation and the differentiation process. Participants are also clarifying the structure of the mathematical expressions involved.

sara_87
Messages
748
Reaction score
0

Homework Statement



How do i differentiate a sum in MATLAB?

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

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

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:

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

so the derivative is:

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

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.
[tex] y_n' = 2x_n + 12x_n^3 + 2x_n[/tex]

Do you then sum over the different y'n or what? That way you'd get
[tex] y' = \sum_{i=1}^n y_i'= 2x_n + \sum_{i=1}^n 12x_i^3 + 2x_n[/tex]

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

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

with respect to xn

I know that this should give:

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

but i want to try to get this result using matlab.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K