- 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 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Divyam
on 30 Oct 2024 at 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 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!