- 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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Divyam
am 30 Okt. 2024 um 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 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!