Borrar filtros
Borrar filtros

How can calculate this formula with matlab?

2 visualizaciones (últimos 30 días)
fede
fede el 5 de Nov. de 2015
Comentada: Torsten el 5 de Nov. de 2015
I have the vectors w(1,n) and σ(n,1). How can calculate this formula?

Respuesta aceptada

Thorsten
Thorsten el 5 de Nov. de 2015
Editada: Thorsten el 5 de Nov. de 2015
You can pull the w_i and sigma_i outside of the sum_j, because the don't depend on j. And you can compute the sum_j nicely as a matrix multiplication of row vector w and column vector sigma.
w = rand(1,10); % sample values for w and s
s = rand(10, 1);
N = numel(w);
y = 0;
for i=1:N-1
y = y + s(i)*w(i)* w(i+1:end)*s(i+1:end);
end
y = 2*y;
  2 comentarios
fede
fede el 5 de Nov. de 2015
give me Error using * Inner matrix dimensions must agree.
Torsten
Torsten el 5 de Nov. de 2015
Note that "w" must be a row vector whereas "s" must be a column vector if you want to use Thorsten's code.
Best wishes
Torsten.

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 5 de Nov. de 2015
sum_total=0.0;
for i=1:(N-1)
sum_j=0.0;
for j=(i+1):N
sum_j = sum_j + w(j)*sigma(j);
end
sum_total = sum_total + w(i)*sigma(i)*sum_j;
end
sum_total = 2.0*sum_total;
Best wishes
Torsten.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by