Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Home Work 1.1 1. Write the command that will create matrix A shown in the format

ID: 3872615 • Letter: H

Question

Home Work 1.1 1. Write the command that will create matrix A shown in the format below using colon operator for the first row A=[0 1 2 3 4 5 6 7] if your K-ID K00789012 0 7 8901 2 2. Now write the command that will access and extract '4' from first row of A' and save it in "B 3. Write the command that will add 'B' with element at location (2,4) of'A and save the result in 4. 5. Extract the row containing your K-ld and save into a new variable called 'kid' What are the dimensions of 'kid'? Hints for HW1.1: Use operator to create the first row of A then switch to the next row using: and then define the numbers of your K-ID separating them using comma or spaces eg. A-[m:n;1 21 Find the row and column number in which '4' is location in A, then form the index pair to address that location eg. A(m,n) is the element in A on the mth row and nh column Add number at location (2,4) of A to B eg. A(m,n)+B .Access all elements only in the 2nd row and extract them to 'kid' eg. A(1,:) will access 1t row Write down the dimension of 'kid' eg. m x n which means m rows by n cofumns

Explanation / Answer

HW1.1

1) The ':' operator generate series as per following specification

"start_value : period : last_value:"

The "period" may be missing.

>>A=[0:7; 0 0 7 8 9 0 1 2];

output:

>> A

A =

0 1 2 3 4 5 6 7
0 0 7 8 9 0 1 2

2) To access the element of the metrix the command is as follow:

variable_name(row_number, column_number).

Here row number of said element is 1 and column number is 5, So the command is:

>>B= A(1,5)

B =

4

Note: We can use ";" at end of command to supress the output display . Like:

>>B= A(1,5);

3)

>> C=B+A(2,4)

C =

12

4)

>> kid=A(2,:)

kid =

0 0 7 8 9 0 1 2

5) Dimention of kid is 1x8

>> [m n]=size(kid)

m =

1


n =

8

HW1.2

1) Dimention of A is 2X8

>> [m n]=size(A)

m =

2


n =

8

2)

>> Z=ones(size(A))

Z =

1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1

>> D=A+Z

D =

1 2 3 4 5 6 7 8
1 1 8 9 10 1 2 3

3)The transpose of a matrix is the matrix with row became column and column became row.

>> E=D'

E =

1 1
2 1
3 8
4 9
5 10
6 1
7 2
8 3

Size of E is 8X2

>> size(E)

ans =

8 2

4)

message='Enter value of f ';
f=input(message)
;

f=f-10;

Enter value of f

5)

message='Enter value of f ';
f=input(message);
disp('"The value entered by the user was"');
fprintf('value of f %d ',f);
f=f-10;
disp('"it was modified to"');
fprintf('Final value of f %d ',f);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote