Differentiate symbolic sum of vectors

3 views (last 30 days)
ata
ata on 19 Dec 2013
Answered: ata on 20 Dec 2013
Hello,
I'm certainly not the first to ask such kind of question, but I can't find appropriate answer...
I'm trying to make a sum of vector elements with symbolic indexes. The sum will then be differentiated in order to find the maximum of it. Here is the "code":
function kd = est(y, p, D)
K0 = size(p,2);
Kp = (size(y,2) - K0)/2;
syms m;
som = 0;
for k=1:Kp-D
val = y(k+m+D+K0)*conj(y(k+m+D+K0))*conj(p(k+D))*p(k);
som = som+val;
end;
Rd(m) = abs(1/(Kp-D)*som);
kd = solve(diff(Rd(m)));
end
y and p are known vectors and D is a scalar. For the moment, the error occurs in the for-loop, stating that "Indexing input must be numeric, logical or ':'."
If I try using the function_handle syntax, then the error occurs when assigning Rd(m)...
Any suggestion would be appreciated.

Accepted Answer

ata
ata on 20 Dec 2013
Thanks for replying!
I needed this summation from the formula I was writing there (something for frame synchronisation with pilot symbols). But I found the solution in the meantime, although not really elegant... I made a loop for the values of 'm', since we can determine limits for this variable with the size of vector y.
Then I don't need to differentiate the expression, indeed.

More Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 19 Dec 2013
y=[1 2 3];
syms m
y(m)
Error using sym/subsindex
Indexing input must be numeric, logical or ':'.
That means you can't use a symbolic index. You should assign a positive integer value to m before using it as an index

Walter Roberson
Walter Roberson on 19 Dec 2013
Rd = abs(1/(Kp-D)*som);
kd = solve(diff(Rd), m);
I have to guess that you want to differentiate with respect to "m", as there are no other variables in your expression.
I do not know how you intend to find a maximum by differentiating: differentiation requires that the function be continuous, but everything you are working with is discrete -- you are passing in vectors for y and p, not functions, and your m is being used as an index, not as a continuous variable.
If you wish to find the largest term, then do not do a summation, just find max() of the sequence of values.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!