Uploaded by Jochem Arends

assignments week2

advertisement
Week 2
Name: Jochem Arends
Student number: 495637
Assignment 1
x = 1:0.2:5;
x(19)
ans = 4.6000
length(x)
ans = 21
The value of the 19th element is 4.6 and the single row contains 21 elements.
Assignment 2
x = linspace(35, 47, 100);
x(19:22)
ans = 1×4
37.1818
37.3030
37.4242
37.5455
Assignment 3
z1 = 3+4i
z1 = 3.0000 + 4.0000i
z2 = -1+1i
z2 = -1.0000 + 1.0000i
% multiplication and division
z1 * z2
ans = -7.0000 - 1.0000i
z1 / z2
ans = 0.5000 - 3.5000i
z3 = 1/(1/z1 + 1/z2)
z3 = -0.6552 + 1.1379i
% the magnitude and angle of z3
1
abs(z3)
ans = 1.3131
angle(z3)
ans = 2.0932
Assignment 4
x = linspace(-5, 5, 100)
x = 1×100
-5.0000
-4.8990
-4.7980
-4.6970
-4.5960
-4.4949
-4.3939
-4.2929
24.0001
23.0206
22.0615
21.1228
20.2046
19.3067
18.4292
y = x.^2
y = 1×100
25.0000
plot(x, y)
title('Graph 1')
xlabel('-5 \leq x \leq 5')
ylabel('x^2')
figure
plot(y)
title('Graph 2')
2
xlabel('0 \leq x \leq 100')
ylabel('y_{x}')
% the first graph shows all elements of variable `x` on the x-axis
% and all elements of variable `y` on the y-axis.
% the second graph shows all the indices of vector `y` on the x-axis
% and all values for the corresponding index at the y-axis.
Assignment 5
w = 0.1:0.05:10
w = 1×199
0.1000
0.1500
0.2000
0.2500
0.3000
0.3500
0.4000
0.4500
z = (1+1i*w)./(1+1i*w-w.^2)
z = 1×199 complex
1.0100 - 0.0010i
1.0225 - 0.0035i
1.0399 - 0.0083i
figure
plot(z)
title('Graph of z')
xlabel('0 < x \leq 1.5')
ylabel('z_{x}')
3
1.0622 - 0.0166i
subplot(2, 1, 1)
plot(abs(z))
title('Graph of the modulus of z')
xlabel('0 < x \leq 200')
ylabel('|z_{x}|')
subplot(2, 1, 2)
plot(angle(z))
title('Graph of argument of z')
xlabel('0 < x \leq 200')
ylabel('angle in radians')
4
Assignment 6
f = logspace(1, 5, 1000)
f = 1×1000
105 ×
0.0001
0.0001
0.0001
0.0001
0.0001
0.0001
0.0001
0.0001
0.0006
0.0006
0.0006
0.0007
0.0007
0.0007
0.0007
R = 10
R = 10
w = 2*pi*f
w = 1×1000
105 ×
0.0006
L = R/(2000*pi)
L = 0.0016
C = 1/(2000*pi*R)
C = 1.5915e-05
z1 = 1./(1i*w*C)
5
z1 = 1×1000 complex
103 ×
0.0000 - 1.0000i
0.0000 - 0.9908i
0.0000 - 0.9817i
0.0000 - 0.9727i
0.0100 + 0.0001i
0.0100 + 0.0001i
0.0100 + 0.0001i
0.0000 + 0.0102i
0.0000 + 0.0103i
z2 = R + 1j*w*L
z2 = 1×1000 complex
103 ×
0.0100 + 0.0001i
H = (z2.*f)./(z1.*f+z2.*f)
H = 1×1000 complex
0.0000 + 0.0100i
0.0000 + 0.0101i
semilogx(f, abs(H))
title('modulus of H(f)')
xlabel('f')
ylabel('modulus')
Assignment 7
6
c = 3*exp(pi/4*1i)-2*exp(-5*pi/6*1i);
r = abs(c)
r = 4.9589
w = 5
w = 5
phi = angle(c)
phi = 0.6808
t = 0:0.01:3;
k = 3*cos(5*t+pi/4)-2*sin(5*t-pi/3);
figure
plot(t, k)
title('Graph of K(t)')
xlabel('t')
ylabel('K_{t}')
,
,
7
figure
plot(t, r*cos(w*t+phi))
title('Graph of u(t)')
xlabel('t')
ylabel('u_{t}')
Assignment 8
a = [2 1 4];
b = [1 -2 3];
c = [4 5 2];
d = a + b - 3 * c;
ab = b - a;
ac = c - a;
bc = c - b;
area = 5.4772
Assignment 9
area = 1/2*norm(cross(ab, ac))
8
area = 5.4772
Assignment 10
A = [1 -6 5; -2 0 2];
A = 2×3
1
-2
-6
0
5
2
B = [3 -1; 4 1];
B = 2×2
3
4
-1
1
% A*B not possible since the column count of A doesn't match the row count
% of B.
B*A
b = 2×3
5
2
-18
-24
13
22
c = A'*B
c = 3×2
-5
-18
23
-3
6
-3
Assignment 11
A = [5 4; 3 6];
b = [4; 16];
A\b
ans = 2×1
-2.2222
3.7778
Assignment 12
% 5x + 4y
% -1x + 3y
% 6x - 2y
% 0x + 42y
A = [5 4 -2
b = [4; 13;
A\b
- 2z + 6w = 4
- 1z + 6w = 13
+ 12z + 16w = 20
+ 2z + 4w = 6
6; -1 3 -1 6; 6 -2 12 16; 0 42 2 4];
20; 6];
ans = 4×1
-1.5157
-0.0329
-0.1269
9
1.9094
Assignment 13
% constants
V1 = 20;
V2 = 12;
V3 = 40;
R1 = 18;
R2 = 10;
R3 = 16;
R4 = 6;
R5 = 15;
R6 = 8;
loop1
loop2
loop3
loop4
=
=
=
=
[R1 + R2, -R2, -R1, 0];
[-R2, R2 + R3, 0, -R3];
[-R1, 0, R1 + R4 + R5, -R5];
[0, -R3, -R5, R3 + R5 + R6];
mat = [loop1;loop2;loop3;loop4];
vec = [V1;-V2;V2-V3;0];
currents = mat\vec
currents = 4×1
-0.9012
-1.5960
-1.6263
-1.2803
Assignment 14
x = linspace(0, 6, 100);
y = sin(x);
dx = diff(x);
dy = diff(y);
10
y_derivative = dy./dx;
n = length(x) - 1;
x_help = x(1:n);
figure
plot(x, y)
title('Graph of sin(x)')
xlabel('x')
ylabel('sin(x)')
figure
plot(x_help, y_derivative)
title('Graph of derivative of sin(x)')
xlabel('x')
ylabel('derivative')
11
Assignment 15
t = linspace(0, 8, 801);
y1 = (t<1).*t;
y2 = (t>=1).*(t<2).*(t.^2-t+1);
y3 = (t>=2).*(t<3).*(3.*t-3);
y4 = (t>=3).*(-t.^2+9*t-12);
y = y1 + y2 + y3 + y4;
figure
plot(t, y)
title('Graph of place-time-function')
xlabel('time')
ylabel('position')
12
y_derivative = diff(y)./diff(t);
t_help = t(1:length(t)-1);
figure
plot(t_help, y_derivative)
title('Graph of derivative of place-time-function')
xlabel('time')
ylabel('place')
13
Assignment 16
% constants
R = 4;
L = 1.3;
t = 0:0.01:2;
i1 = (t<=0.5).*(12/R).*(1-exp(-R.*t/L));
i2 = (t>0.5).*exp(-R.*t/L)*(12/R)*(exp(R/(2*L))-1);
i = i1 + i2;
figure
plot(t, i)
title('Graph of current')
xlabel('time')
ylabel('current (A)')
14
15
Download