1-2 | Matlab stuff Flashcards

1
Q

Creating matrices:

brackets to use?

A

square [ ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Creating matrices

separator for columns?

A

space or comma

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Creating matrices

separator for rows?

A

;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Matlab function for the reduce row echelon form?

A

rref()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Matlab function for the rank of a matrix?

A

rank()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

sum of a vector A

A

sum(A)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define the vector C = [1, 2, …, 1030]

A

C = 1:1030

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Read out the first three and the last thirty elements of C = [1, 2, …, 1030], such that you obtain a new vector X = [1,2,3,1001,1002,…,1030].

A

X = C([1:3 end-29:end])

or

X = C([1:3 1001:1030])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Read out all the even elements (divisible by 2) of C = [1, 2, …, 1030]. You can use functions such as mod or rem to find even elements.

A

C(mod(C,2)==0)

or

C(find(mod(C,2)==0))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Replace the fifth, sixth, …, twelfth elements of C = [1, 2, …, 1030] with the vector [10,15,….,45].

A

C(5:12) = 10:5:45

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Remove all variables from your workspace.

A

clear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Create a zero vector with 1 row and 10 columns

A

zeros(1,10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Create a vector B = [-21, -20, …, -12]

A

B = -21:-12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Create a vector A = [2, 4, 6,…,20]

A

A = 2:2:20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Create a matrix MatX whose rows are A, B and C, concatenated in that order.

A

MatX = [A; B; C]

15
Q
A
16
Q

Read out all the elements of the second row of MatX.

A

MatX(2,:)

17
Q

Read out the first five elements of rows one and two of matrix MatX

A

MatX(1:2,1:5)

18
Q

Replace the second column of MatX with zeros using the command zeros.

A

MatX(:,2) = zeros

or

MatX(:,2) = zeros(size(MatX,1),1)

19
Q

Replace the element in the second row, third column, with −∞ (-Inf).

A

MatX(2,3) = -Inf

20
Q

Create an identity matrix with m rows and n columns

A

eye(m,n)

21
Q

Transpose of a matrix A

A

A’

22
Q

extract negative part of vector A

A

A(A<0)

22
Q

get the position where value in B is 2

A

find(B==2)

23
Q

extract the part of B that has values different from 1 and save it in new variable

A

X = B(B~=1)

24
Q

What are the elementwise operations?

What is requirement?

A

A . ± B = A ± B

A .∗B

A ./B

A .^2

The sizes of the two matrices in element-wise operations must be exactly the same.

25
Q

How to find input and output of a function?

A

help functionname

26
Q
A
26
Q

save workspace into a file

A

save myfile.mat

27
Q

Maria has an online shop where she sells hand made paintings and cards. She sells the painting for 50€ and the card for 20€. It takes her 2 hours to complete one painting and 30 minutes to make a single card. She also has a day job and makes paintings and cards in her free time. Thus, she cannotspend more than 15 hours a week to make paintings and cards.

Additionally, she should make not more than 10 paintings and cards per week. She makes a profit of 25€ on paintings and 15€ on each card. How many paintings and cards should she make each week to maximize her profit?

Write down the LP model

Use linprog() function in MATLAB to check the solution for point b.

A

% max z = 25P + 15C
% 2P + 0.5C <= 15 (time in hours)
% P + C <= 10 (maximum products / week)
% P >= 0
% C >= 0

f = [-25 -15];
A = [2 0.5; 1 1];
b = [15; 10];

x = linprog(f, A, b);

28
Q

A store has requested a manufacturer to produce pants and sports jackets.

For materials, the manufacturer has 750m2 of cotton textile and 1000m2 of polyester. Every pair of pants (1 unit) needs 1m2 of cotton and 2m2 of polyester. Every jacket needs 1.5m2 of cotton and 1m2 of polyester. The price of the pants is fixed at 50€ and the jacket 40€. What is the number of pants and jackets that the manufacturer must give to the stores so that these items obtain a maximum sale?

Write down the LP model of the problem above in standard form.

Use linprog() function in MATLAB to solve the LP.

A

f = [-50 -40];
A = [1 1.5;2 1];
b = [750;1000];
Aeq = [];
beq = [];
lb = [0;0];
ub = [1000;1000];

[x,fval] = linprog(f,A,b,Aeq,beq,lb,ub);
maximum_sale = -fval
fval == f*x

29
Q
A