Differentiate symbolic sum of vectors
Show older comments
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
More Answers (2)
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
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.
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!