How to create vector which is linear combination of a matrix

조회 수: 54 (최근 30일)
aliza mustafa
aliza mustafa 2022년 8월 30일
댓글: aliza mustafa 2022년 8월 30일
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
Karim
Karim 2022년 8월 30일
You will need to expand a bit on why it doesn't seem right ... what would you expect as output?
aliza mustafa
aliza mustafa 2022년 8월 30일
I was making mistake in making the vector. I got it done this way:
vec= 2*M(:,1) + 3*M(:,2) + 4*M(:,3);
Thanks :)

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2022년 8월 30일
Perhaps you instead meant to have,
M = [1,2,3; 4,5,6; 7,8,9];
vec=M*[2;3;4]
vec = 3×1
20 47 74

추가 답변 (1개)

Chunru
Chunru 2022년 8월 30일
M = [1,2,3; 4,5,6; 7,8,9]
M = 3×3
1 2 3 4 5 6 7 8 9
vec= sum([2*M(:,1) 3*M(:,2) 4*M(:,3)], 2)
vec = 3×1
20 47 74
% Alternatively
vec =M*[2; 3; 4]
vec = 3×1
20 47 74

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by