What is wrong in this code? trying to code the equation and j is time instant

4 visualizaciones (últimos 30 días)
Aastha Singla
Aastha Singla el 6 de Nov. de 2022
Respondida: Divyam el 30 de Oct. de 2024 a las 5:43
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

Respuestas (1)

Divyam
Divyam el 30 de Oct. de 2024 a las 5:43
Here are a few corrections you can make in your code:
  • 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.
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);
5 8 5 8

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by