# Given a Matrix A, create a row vector of 1s that has same number of elements as A has rows

1,311 views (last 30 days)
Gaurav Srivastava on 4 Jun 2019
Commented: Basil Alabdali on 14 Feb 2022
Given a Matrix A, Create a row vector of 1's that has same number of elements as A has rows. Create a column vector of 1's that has the same number of elements as A has columns. Using matrix multiplication, assign the product of the row vector, the matrix A, and the column vector (in this order) to the variable result. A = [1:5; 6:10; 11:15; 16:20];
Basil Alabdali on 14 Feb 2022
V1 = [2 4 7 9]; V2 = V1’; M1 = [2 5 6; 3 7 9]; M2 = M1’;
4.a) Element-by-element addition of V1 and V2, and the result must be row vector.
4.b) Element-by-element multiplication of V1 and V2, and the result must be column vector.
4.c) Rise each element in V1 to the power of 3, and the result must be column vector.
4.d) Matrix multiplication between V1 and V2 respectively.
4.e) Repeat part (d) without using matrix multiplication. Hint: compare part (d) with part (b).
4.f) Is it valid to perform element-by-element division between M1 and M2 respectively? If yes, do the element-by-element division.
4.g) Matrix multiplication between M1 and M2.
4.h) Repeat part (g) without using matrix multiplication. Hint: see part (e).

Manali Gupta on 20 May 2021
Edited: MathWorks Support Team on 20 May 2021
R_vector = ones(1,size(A,1)); C_vector=ones(size(A,2),1); result = R_vector*A*C_vector;
Habib Ali on 19 Jan 2021
A = [1:5; 6:10; 11:15; 16:20];
r=[1 1 1 1]
y=[1;1;1;1;1]
result=r*A*y

### More Answers (17)

Alex Mcaulley on 4 Jun 2019
I think the goal of this forum is not to do anyone's homework, but to solve generic questions about Matlab that can help more users. This exercise is very simple, anyone who has ever used Matlab could do it, so, I think the best thing we can do is help @Gaurav to know how to learn the basics of Matlab.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 19 Apr 2021
ones(1,size(A, 1))

Sudhanshu Rasal on 5 May 2020
Edited: Sudhanshu Rasal on 5 May 2020
Simple way to do this question is
X=[1 1 1 1]
Y=[1;1;1;1;1]
result=X*A*Y ????????
Avishkar patel on 30 Aug 2020
Edited: Walter Roberson on 11 Apr 2021
X=[1 1 1 1]
Y=[1;1;1;1;1]
result=X*A*Y

Khom Raj Thapa Magar on 28 Aug 2020
Given A = [1:5; 6:10; 11:15; 16:20];
row_vec = ones(1,size(A,1))
column_vec = ones(length(A),1)
result = row_vec * A * column_vec
Output:
row_vec =
1 1 1 1
column_vec =
1
1
1
1
1
result =
210

Tushar Parmar on 11 May 2020
A = [1:5; 6:10; 11:15; 16:20]
B(1:4)=1;
f=B*A
C(1:5)=1;
C=C'
result=f*C
Tharindu Priyankara on 29 Aug 2020
THANKS

Arakala Gautham on 4 Apr 2020
R_vector = ones(1,size(A,1));
C_vector=ones(size(A,2),1);
result = R_vector*A*C_vector;
remove that colon(;) from the last line

Gaurav Saini on 16 May 2020

given matrix A create a row vector of 1's that has some number of elements as A has rows in matlab programming

##### 1 CommentShowHide None
Steven Lord on 16 May 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Rishabh Nirala on 20 May 2020
A = [1:5; 6:10; 11:15; 16:20];
C = [1;1;1;1;1]
R = [1 1 1 1 ]
P = R * A
result = P*C

Hardik Mittal on 26 May 2020
Input:
A = [1:5; 6:10; 11:15; 16:20]
B(1:4)=1;
D=B*A
C(1:5)=1;
C=C'
result=D*C
Solution
A =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
f =
34 38 42 46 50
C =
1
1
1
1
1
result =
210

Sneham Shrikant Vaidya on 27 May 2020
A = [1:5; 6:10; 11:15; 16:20];
A
x = [1 1 1 1 ]
y = [1;1;1;1;1]
z = A*y
result =x*z
// you can also perform this way as we know z =(lxm)*(mxn) so we first multiply A*y as their inner dimension ara same
then we obtain result matrix z that has inner dimension equal to x so now we can multiply x*z to get final ans

VISHWA D on 22 Jun 2020
A = [1:5; 6:10; 11:15; 16:20];
row_vector=[1 1 1 1 1]
col_vector=[1; 1; 1; 1]
result=(row_vector*(A'))*(col_vector)
##### 1 CommentShowHide None
lijuan wang on 27 Aug 2020
I thought the assignment has a wrong requirement, right?
we should create a vector which has the some rows as A. So it should be row_vector=[1 1 1 1]'?

Aditya Tiwari on 15 Sep 2020
R_vector = ones(1,size(A,1));
C_vector=ones(size(A,2),1);
result = R_vector*A*C_vector;

Razieh Gholami on 23 Dec 2020
Determine the elements of A^T, Adj A, A^−1
A =
1 2 1
2 1 0
−1 0 1
##### 1 CommentShowHide None
Walter Roberson on 30 Mar 2021

Mona Nasser on 9 Mar 2021
Consider the following MATLAB program: x = [ 1 2 ]; y = [ 3 4 ]; z = [ x [ y ; y ] ]; What is the value of z after this program executes?
##### 1 CommentShowHide None
Walter Roberson on 30 Mar 2021

Zyad Alhazme on 27 Mar 2021
Generate 2 vectors, say A and B; of the same length and add them. Then subtract them
##### 1 CommentShowHide None
Walter Roberson on 30 Mar 2021

qasim alsubayq on 30 Mar 2021
Write a MATLAB program that computes the value of the Gaussian distribution N(m, S), at a given vector x where:
m=[0 1] T, s=[1 0; 0 1], x=[1 1] T
##### 1 CommentShowHide None
Walter Roberson on 30 Mar 2021

samkit jain on 8 Apr 2021
Sir, MATLAB ( Ann toolbox) ke jariye kya hum data ko predict KR skte h kya ... Ye Dekh Kar bta do yarr Hume Thora Man lo hamare pass 2000 s lekar 2020 Ka data h Kisi bhi cheez Ka aur 2021 s 2025 tk Ka kya values aayega ye pta KR skte h kya usse
Walter Roberson on 9 Apr 2021
You can predict it using something like NARX. I already posted the link.

Javeria Riaz on 5 Jul 2021
Generate column vector for the first thirty natural numbers
##### 1 CommentShowHide None
Walter Roberson on 5 Jul 2021
randperm(30).'