Multiplication implementation help?

Hello Experts,
I need to write MATLAB code and to build a product like this:
for i from 1 to d, multiplication (x(i)-x(j)). x is a row vector of size d.
Here is what I did:
m = 0;
for i=1:d
for j=1:d
if i~=j
m = prod(x(i)-x(j));
end
end
end
But I am not sure if I am right...can you please help me with this?

2 comentarios

Fangjun Jiang
Fangjun Jiang el 6 de Oct. de 2011
format your code next time
Steve
Steve el 6 de Oct. de 2011
But am I right?

Iniciar sesión para comentar.

 Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 6 de Oct. de 2011

1 voto

You need to initialize m=1 and then do m=m*(x(i)-x(j)), or m=prod([m,x(i)-x(j)]). Use a test vector of x to verify the result.

Más respuestas (0)

Categorías

Más información sobre Testing Frameworks en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 6 de Oct. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by