Acessing numerical matrix in symsum function

2 次查看(过去 30 天)
Hello,
I'm having some trouble trying to run this code
clc;
clear;
close all
%%Imagem
IM = [1 2 3; 4 5 6; 7 8 9]
im = sqrt(-1);
%%Data
ind = 3;
omeg = 2^(-((ind+2)/2));
sig = (2*pi^2)/omeg;
thet = 0;
%%first
% J = sum(0,k)[f(k,y) H(x - k) S(x-k)
y = 0;
syms k x
%soma = IM(y+1,k+1)*exp(im*omeg*sin(thet))*exp(-0.5*((x-k)/sig)^2);
J0 = symsum(IM(y+1,k+1)*exp(im*omeg*sin(thet))*exp(-0.5*((x-k)/sig)^2), k, 0, 3)
I got the following error:
Error using sym/subsindex (line 766) Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
How can I get values from a numeric matrix in symbolic sum?
Thank you

采纳的回答

Walter Roberson
Walter Roberson 2018-4-28
It is never valid to index an array at a symbolic variable.
Instead, if you have fixed endpoints, generate a vector of the values over the range, and the sum() the vector.
symsum() is for finding closed form formulas for summations, not for adding definite terms. For example if you were to pass the taylor expansion for sin(x) to symsum then it would be able to recover sin(x).

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by