- The size of vector x should be , i.e. not .
- Matrix "H" and variable "k" need to be defined appropriately.
- No need to use "i" as a symbolic variable, it can function perfectly fine as a loop variable.
- Indexing used in the loop is incorrect and needs to be fixed.
- The sum can be directly computed numerically using a loop and "symsum" is not needed for the same.
What is wrong in this code? trying to code the equation and j is time instant
4 次查看(过去 30 天)
显示 更早的评论
N= 10;
M = 4;
data = randi([0,3],999,1);
u = pammod(data,M);
x= zeros(24,24);%estimated
for i = 1:N
syms i
for j = 1:N
H(:,k)= symsum ((x(i(:,j)))*(x(i+N(:,j))),i,1,N);
end
end
0 个评论
回答(1 个)
Divyam
2024-10-30,5:43
Here are a few corrections you can make in your code:
x = [1; 2; 3; 4];
total_size = size(x, 1);
N = total_size/2;
% Initialize output matrix
H = zeros(N, N);
% Compute matrix H
for i = 1:N
for j = 1:N
% Calculate the sum for each element
sum_val = 0;
for k = 1:N
% Ensure we don't exceed vector bounds
if (k + j - 1) <= total_size
sum_val = sum_val + x(k) * x(k + j - 1);
end
end
H(i, j) = sum_val;
end
end
disp(H);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!