Matlab Sheet 2 Arrays









matlab-basic-functions-reference.pdf

mathworks.com/help/matlab. MATLAB® Basic Functions Reference Defining and Changing Array Variables ... Create vector of n logarithmically spaced.
matlab basic functions reference


Functions for building vectors colon(:)linspace

https://math.aalto.fi/~kuorttj1/scip2017/Lecture1_part2.pdf


MATLAB Commands and Functions

Matrix Commands for Solving Linear Equations / 6 Lists all MATLAB files in the current directory. wklread ... Creates logarithmically spaced vector.
MatlabCommands


Matlab Sheet 2 Arrays

Matlab Sheet 2 Solution. Matlab Sheet 2. Arrays. 1. a. Create the vector x having 50 logarithmically spaced values starting at. 10 and ending at 1000.
Matlab Sheet solution





Chapter 2

The term array is frequently used in MATLAB to refer generically to a matrix or a vector vector; logspace(xy
ch


matlab: 'MATLAB' Emulation Package

01-Jun-2022 MATLAB logspace function. Description. Generate logarithmically spaced vectors. Usage logspace(a b
matlab


USER'S GUIDE FOR vectfit3.m (Fast Relaxed Vector Fitting)

This guide describes a Matlab routine vectfit3.m Complex conjugate pairs
vectfit userguide


MATLAB FORMULA LIST

logspace(X1 X2) generates a row vector of 50 logarithmically equally spaced points between decades 10^X1 and 10^X2. If X2 is pi
MATLAB formulas list





Matlab Basics Tutorial

make a time vector (the semicolon after each statement tells Matlab we don't want to see all Use logspace to generate logarithmically spaced frequency.
Matlab Tutorial


List of Matlab commands

List of Matlab commands. General Purpose Vector Matrices and Arrays. Array Commands ... logspace Creates log spaced vector. y = logspace(a
functionslist cols


216827 Matlab Sheet 2 Arrays Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 1 of 32 Matlab Sheet 2 Solution

Matlab Sheet 2

Arrays

1. a. Create the vector x having 50 logarithmically spaced values starting at

10 and ending at 1000.

b. Create the vector x having 20 logarithmically spaced values starting at

10 and ending at 1000.

The m-file:

x1=logspace(1,3) x2=logspace(1,3,20)

2. Create a row vector that has the following elements: 8, 10/4, 12ൈ1.4, 51,

tan 85°,ξʹ͸ , and 0.15.

The m-file:

row=[8 10/4 12*1.4 51 tand(85) sqrt(26) 0.15]

In Command Window:

row =

8 2.5 16.8 51 11.43 5.099 0.15

3. Create a row vector in which the first element is 1 and the last element is 43,

The m-file:

row=1:6:43

In Command Window:

row =

1 7 13 19 25 31 37 43

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 2 of 32 Matlab Sheet 2 Solution

4. Use a single command to create a row vector (assign it to a variable named b)

with 11 elements, such that b = 0 2 4 6 8 10 12 9 6 3 0

Do not type the vector explicitly.

The m-file:

b=[0:2:12 9:-3:0]

In Command Window:

b =

0 2 4 6 8 10 12 9 6 3 0

5. Create two row vectors: a=2:3:17 and b=3:4:15. Then, by only using the name

of the vectors (a and b), create a row vector c that is made from the elements of a followed by the elements of b.

The m-file:

a=2:3:17; b=3:4:15; c=[a,b]

In Command Window:

c =

2 5 8 11 14 17 3 7 11 15

name of the vectors (a and b), create a column vector c that is made from the elements of a followed by the elements of b.

The m-file:

a=[2:3:17]'; b=[3:4:15]'; c=[a;b]

In Command Window:

c = 2 5 8 11 Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 3 of 32 Matlab Sheet 2 Solution 14 17 3 7 11 15

7. A Type this matrix in MATLAB and use MATLAB to carry out the following

Instructions:

a. Create a vector v consisting of the elements in the second column of A. b. Create a vector w consisting of the elements in the second row of A.

The m-file:

A = [3,7,-4,12;-5,9,10,2;6,13,8,11;15,5,4,1];

v = A(:,2) w = A(2,:)

In Command Window:

v = 7 9 13 5 w = -5 9 10 2 Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 4 of 32 Matlab Sheet 2 Solution

8. Create the following matrix by using vector notation for creating vectors with

constant spacing and/or the linspace command. Do not type individual elements explicitly.

The m-file:

A=[130:-20:10; linspace(1,12,7); 12:10:72]

In Command Window:

A= A =

130 110 90 70 50 30 10

1. 2.8333 4.6667 6.5000 8.3333 10.1667 12.0000

12 22 32 42 52 62 72

9. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

%alternative C = [linspace(7,7,5); linspace(7,7,5)]

C=7*ones(2,5)

In Command Window:

C =

7 7 7 7 7

7 7 7 7 7

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 5 of 32 Matlab Sheet 2 Solution

10. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

D=[zeros(3,4) [8:-1:6]']

In Command Window:

D =

0 0 0 0 8

0 0 0 0 7

0 0 0 0 6

11. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

F=[linspace(0,0,5); zeros(3,2) [1:3;10:-2:6;20:6:32]']

In Command Window:

F =

0 0 0 0 0

0 0 1 10 20

0 0 2 8 26

0 0 3 6 32

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 6 of 32 Matlab Sheet 2 Solution

12. Compute the length and absolute value of the following vectors:

The m-file:

x = [2,4,7]; ans1=length(x) ans2=abs(x) y=[2,-4,7]; ans3=length(y) ans4=abs(y) z=[5+3i,-3+4i,2-7i]; ans5=length(z) ans6=abs(z)

In Command Window:

ans1 = 3 ans2 = 2 4 7 ans3 = 3 ans4 = 2 4 7 Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 1 of 32 Matlab Sheet 2 Solution

Matlab Sheet 2

Arrays

1. a. Create the vector x having 50 logarithmically spaced values starting at

10 and ending at 1000.

b. Create the vector x having 20 logarithmically spaced values starting at

10 and ending at 1000.

The m-file:

x1=logspace(1,3) x2=logspace(1,3,20)

2. Create a row vector that has the following elements: 8, 10/4, 12ൈ1.4, 51,

tan 85°,ξʹ͸ , and 0.15.

The m-file:

row=[8 10/4 12*1.4 51 tand(85) sqrt(26) 0.15]

In Command Window:

row =

8 2.5 16.8 51 11.43 5.099 0.15

3. Create a row vector in which the first element is 1 and the last element is 43,

The m-file:

row=1:6:43

In Command Window:

row =

1 7 13 19 25 31 37 43

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 2 of 32 Matlab Sheet 2 Solution

4. Use a single command to create a row vector (assign it to a variable named b)

with 11 elements, such that b = 0 2 4 6 8 10 12 9 6 3 0

Do not type the vector explicitly.

The m-file:

b=[0:2:12 9:-3:0]

In Command Window:

b =

0 2 4 6 8 10 12 9 6 3 0

5. Create two row vectors: a=2:3:17 and b=3:4:15. Then, by only using the name

of the vectors (a and b), create a row vector c that is made from the elements of a followed by the elements of b.

The m-file:

a=2:3:17; b=3:4:15; c=[a,b]

In Command Window:

c =

2 5 8 11 14 17 3 7 11 15

name of the vectors (a and b), create a column vector c that is made from the elements of a followed by the elements of b.

The m-file:

a=[2:3:17]'; b=[3:4:15]'; c=[a;b]

In Command Window:

c = 2 5 8 11 Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 3 of 32 Matlab Sheet 2 Solution 14 17 3 7 11 15

7. A Type this matrix in MATLAB and use MATLAB to carry out the following

Instructions:

a. Create a vector v consisting of the elements in the second column of A. b. Create a vector w consisting of the elements in the second row of A.

The m-file:

A = [3,7,-4,12;-5,9,10,2;6,13,8,11;15,5,4,1];

v = A(:,2) w = A(2,:)

In Command Window:

v = 7 9 13 5 w = -5 9 10 2 Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 4 of 32 Matlab Sheet 2 Solution

8. Create the following matrix by using vector notation for creating vectors with

constant spacing and/or the linspace command. Do not type individual elements explicitly.

The m-file:

A=[130:-20:10; linspace(1,12,7); 12:10:72]

In Command Window:

A= A =

130 110 90 70 50 30 10

1. 2.8333 4.6667 6.5000 8.3333 10.1667 12.0000

12 22 32 42 52 62 72

9. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

%alternative C = [linspace(7,7,5); linspace(7,7,5)]

C=7*ones(2,5)

In Command Window:

C =

7 7 7 7 7

7 7 7 7 7

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 5 of 32 Matlab Sheet 2 Solution

10. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

D=[zeros(3,4) [8:-1:6]']

In Command Window:

D =

0 0 0 0 8

0 0 0 0 7

0 0 0 0 6

11. Create the following matrix by typing one command. Do not type individual

elements explicitly.

The m-file:

F=[linspace(0,0,5); zeros(3,2) [1:3;10:-2:6;20:6:32]']

In Command Window:

F =

0 0 0 0 0

0 0 1 10 20

0 0 2 8 26

0 0 3 6 32

Faculty of Engineering Spring 2017 Mechanical Engineering Department Dr./ Ahmed Nagib Elmekawy 6 of 32 Matlab Sheet 2 Solution

12. Compute the length and absolute value of the following vectors:

The m-file:

x = [2,4,7]; ans1=length(x) ans2=abs(x) y=[2,-4,7]; ans3=length(y) ans4=abs(y) z=[5+3i,-3+4i,2-7i]; ans5=length(z) ans6=abs(z)

In Command Window:

ans1 = 3 ans2 = 2 4 7 ans3 = 3 ans4 = 2 4 7
  1. log spaced vector matlab
  2. logarithmic spaced vector matlab