- 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!