How to create vector which is linear combination of a matrix
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
aliza mustafa
el 30 de Ag. de 2022
Comentada: aliza mustafa
el 30 de Ag. de 2022
Hi,
I have my matrix M as:
M = [1,2,3; 4,5,6; 7,8,9];
I am trying to create a vector that is a linear combination of the columns of M. I am doing it this way:
vec= [2*M(:,1); 3*M(:,2); 4*M(:,3)];
Its resulting in:
vec =
2
8
14
6
15
24
12
24
36
It doesn't seem right to me. Can you please help me in that? Any help will be really appreciated. Thanks in advance.
2 comentarios
Karim
el 30 de Ag. de 2022
You will need to expand a bit on why it doesn't seem right ... what would you expect as output?
Respuesta aceptada
Matt J
el 30 de Ag. de 2022
Perhaps you instead meant to have,
M = [1,2,3; 4,5,6; 7,8,9];
vec=M*[2;3;4]
Más respuestas (1)
Chunru
el 30 de Ag. de 2022
M = [1,2,3; 4,5,6; 7,8,9]
vec= sum([2*M(:,1) 3*M(:,2) 4*M(:,3)], 2)
% Alternatively
vec =M*[2; 3; 4]
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!