Skip to content

Commit 5a46017

Browse files
authored
Add files via upload
0 parents  commit 5a46017

35 files changed

+671
-0
lines changed

Assignment_LinearEquationsmlx.mlx

70 KB
Binary file not shown.

Assignment_LinearEquationsmlx.pdf

371 KB
Binary file not shown.

Assignment_NumericalIntegration.mlx

5.44 KB
Binary file not shown.

Assignment_NumericalIntegration.pdf

127 KB
Binary file not shown.

Assignment_ODE_bc.mlx

136 KB
Binary file not shown.

Assignment_ODE_bc.pdf

295 KB
Binary file not shown.

Assignment_dataIO.mlx

441 KB
Binary file not shown.

Assignment_dataIO.pdf

1020 KB
Binary file not shown.
Binary file not shown.

Homework_01.doc

79.5 KB
Binary file not shown.

Homework_01.m

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
% -----------------------------------------
2+
% HW1
3+
% LiXin
4+
% 2022/2/18
5+
% -----------------------------------------
6+
clear all; close all; clc
7+
8+
%% Problem 1
9+
10+
% 1
11+
r=0.15; % interest rate
12+
L=50000; % loan amount
13+
N=[0.5:1/12:20]; % number of years
14+
PN=(r*L*(1+r/12).^(12*N))./(12*((1+r/12).^(12*N)-1)) % monthly payment
15+
16+
% 2
17+
plot(N, PN) % plot the monthly payment and the number of years
18+
19+
% 3
20+
text(10,1000,"LiXin")
21+
22+
%% Problem 2
23+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
24+
% a
25+
A=[20 4 2 6; 6 37 2 3;8 5 9 9] % create the matrix
26+
% b
27+
x1=A(1,:) % assign the first row of A to a vector called x1
28+
% c
29+
y=A([end-1 end],:) % assign the last 2 rows of A to an array called y
30+
% d
31+
B=A(:,2:2:size(A,2)) % assign the even-numbered columns of A to an array called B
32+
% e
33+
C=A' % assign the transpose of A to C
34+
% f
35+
reciprocal = 1./A % compute the reciprocal of each element of A
36+
% g
37+
A(3, 2)=100 % change the number in column 2, row 3 of A to 100
38+
39+
%% Problem 3
40+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
41+
% a
42+
figure % create an empty figure
43+
44+
% b
45+
t=0:0.01:2*pi; % create a vector contains numbers range from 0 to 2*pi
46+
y=sin(4*t).*cos(2*t); % calculate the result of the function according to the scope
47+
ax1=subplot(1,2,1);
48+
plot(t,y) % normal plot
49+
ax2=subplot(1,2,2);
50+
polarplot(t,y) % polar plot
51+
52+
% c
53+
legend(ax1,'y^k_{max}=sin(4t)cos(2t)') % put legend on the first subgraph
54+
55+
% d
56+
grid(ax1, 'on') % grid on the first subgraph
57+
58+
% e
59+
text(0,0,'Lixin') % text on the second subgraph
60+
61+
%% Problem 4
62+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
63+
% a
64+
num=input('Enter a number: ');
65+
66+
% b
67+
num_cm=num * 2.54; % convert to cm
68+
fprintf('%.2f inches is %.2f cm\n', num, num_cm)
69+
70+
% c
71+
num_mm=num_cm * 10; % the number converted to mm
72+
formatSpec='%.2f';
73+
str = [num2str(num, formatSpec), ' is also ', num2str(num_mm, formatSpec), 'mm'];
74+
disp(str)
75+
76+
%% Problem 5
77+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
78+
Nr = logspace(4,8,100); % Reynolds number
79+
for De = [20 100 1000 1000 100000] % D/epsilon
80+
f = 0.25./(log(1/(3.7*De)+5.74./Nr.^0.9)/log(10)).^2;
81+
loglog(Nr, f)
82+
hold on
83+
end
84+
grid on
85+
grid minor
86+
Nr=[1e2:0.2e4];
87+
f = 64./Nr;
88+
plot(Nr, f) % plot f = 64 / Nr
89+
title('Moody''s Diagram')
90+
ylabel('Friction Factor')
91+
xlabel('Reynolds Number N_R')
92+
legend('D/\epsilon = 20', 'D/\epsilon = 100', 'D/\epsilon = 1000', 'D/\epsilon = 10000', 'D/\epsilon = 100000','Laminar flow',...
93+
'Location','southwest')
94+
text(1e7,0.08,'Lixin') % print my name
95+
xlim([0.8e3 1e8])
96+
ylim([0.8e-2 1e-1])% adjust axis limits
97+
98+
%% Problem 6
99+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
100+
[x, y]=meshgrid(-2:0.1:2);
101+
f=50*y.^2.*exp(-x.^2-0.5*y.^2);
102+
C=x.*y;
103+
surf(x,y,f,C)
104+
xlabel('x');
105+
ylabel('y');
106+
zlabel('f(x,y) = 50y^2e^{-x^2-0.5y^2}');
107+
title('My Plot Title')
108+
109+

Homework_01.pdf

55.7 KB
Binary file not shown.

Homework_01.txt

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
% -----------------------------------------
2+
% HW1
3+
% LiXin
4+
% 2022/2/18
5+
% -----------------------------------------
6+
clear all; close all; clc
7+
8+
%% Problem 1
9+
10+
% 1
11+
r=0.15; % interest rate
12+
L=50000; % loan amount
13+
N=[0.5:1/12:20]; % number of years
14+
PN=(r*L*(1+r/12).^(12*N))./(12*((1+r/12).^(12*N)-1)) % monthly payment
15+
16+
% 2
17+
plot(N, PN) % plot the monthly payment and the number of years
18+
19+
% 3
20+
text(10,1000,"LiXin")
21+
22+
%% Problem 2
23+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
24+
% a
25+
A=[20 4 2 6; 6 37 2 3;8 5 9 9] % create the matrix
26+
% b
27+
x1=A(1,:) % assign the first row of A to a vector called x1
28+
% c
29+
y=A([end-1 end],:) % assign the last 2 rows of A to an array called y
30+
% d
31+
B=A(:,2:2:size(A,2)) % assign the even-numbered columns of A to an array called B
32+
% e
33+
C=A' % assign the transpose of A to C
34+
% f
35+
reciprocal = 1./A % compute the reciprocal of each element of A
36+
% g
37+
A(3, 2)=100 % change the number in column 2, row 3 of A to 100
38+
39+
%% Problem 3
40+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
41+
% a
42+
figure % create an empty figure
43+
44+
% b
45+
t=0:0.01:2*pi; % create a vector contains numbers range from 0 to 2*pi
46+
y=sin(4*t).*cos(2*t); % calculate the result of the function according to the scope
47+
ax1=subplot(1,2,1);
48+
plot(t,y) % normal plot
49+
ax2=subplot(1,2,2);
50+
polarplot(t,y) % polar plot
51+
52+
% c
53+
legend(ax1,'y^k_{max}=sin(4t)cos(2t)') % put legend on the first subgraph
54+
55+
% d
56+
grid(ax1, 'on') % grid on the first subgraph
57+
58+
% e
59+
text(0,0,'Lixin') % text on the second subgraph
60+
61+
%% Problem 4
62+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
63+
% a
64+
num=input('Enter a number: ');
65+
66+
% b
67+
num_cm=num * 2.54; % convert to cm
68+
fprintf('%.2f inches is %.2f cm\n', num, num_cm)
69+
70+
% c
71+
num_mm=num_cm * 10; % the number converted to mm
72+
formatSpec='%.2f';
73+
str = [num2str(num, formatSpec), ' is also ', num2str(num_mm, formatSpec), 'mm'];
74+
disp(str)
75+
76+
%% Problem 5
77+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
78+
Nr = logspace(4,8,100); % Reynolds number
79+
for De = [20 100 1000 1000 100000] % D/epsilon
80+
f = 0.25./(log(1/(3.7*De)+5.74./Nr.^0.9)/log(10)).^2;
81+
loglog(Nr, f)
82+
hold on
83+
end
84+
grid on
85+
grid minor
86+
Nr=[1e2:0.2e4];
87+
f = 64./Nr;
88+
plot(Nr, f) % plot f = 64 / Nr
89+
title('Moody''s Diagram')
90+
ylabel('Friction Factor')
91+
xlabel('Reynolds Number N_R')
92+
legend('D/\epsilon = 20', 'D/\epsilon = 100', 'D/\epsilon = 1000', 'D/\epsilon = 10000', 'D/\epsilon = 100000','Laminar flow',...
93+
'Location','southwest')
94+
text(1e7,0.08,'Lixin') % print my name
95+
xlim([0.8e3 1e8])
96+
ylim([0.8e-2 1e-1])% adjust axis limits
97+
98+
%% Problem 6
99+
clear all; close all; clc % erase all the workspace data, command window output, and close all figures
100+
[x, y]=meshgrid(-2:0.1:2);
101+
f=50*y.^2.*exp(-x.^2-0.5*y.^2);
102+
C=x.*y;
103+
surf(x,y,f,C)
104+
xlabel('x');
105+
ylabel('y');
106+
zlabel('f(x,y) = 50y^2e^{-x^2-0.5y^2}');
107+
title('My Plot Title')
108+
109+

Homework_02.mlx

241 KB
Binary file not shown.

Homework_02.pdf

679 KB
Binary file not shown.

Homework_02.txt

241 KB
Binary file not shown.

ICE 1.pptx

65.4 KB
Binary file not shown.

ICE01.m

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%% Problem 1
2+
Name = "LiXin"
3+
4+
%% Problem 2
5+
ans = 15 / (8 * 10)
6+
7+
%% Problem 3
8+
a = 6
9+
10+
%% Problem 4
11+
c = a * 2
12+
13+
%% Problem 5
14+
w = [18 12 1; 4 8 1]
15+
16+
%% Problem 6
17+
ans = w.^3
18+
19+
%% Variables and Arrays
20+
% Problem 1
21+
M12 = zeros(5, 6);
22+
M12 = M12 + 12
23+
% Problem 2
24+
% a
25+
A = rand(randi(9)+1, randi(9)+1)
26+
% b
27+
rows = size(A, 1);
28+
columns = size(A, 2);
29+
% c
30+
w = A(rows, columns - 1);
31+
% Problem 3
32+
% a
33+
clc
34+
% b
35+
% LiXin HW1, Problem 3
36+
% c
37+
y = [ 2 3 4; 5 6 7];
38+
% d
39+
ra = y + 16;
40+
% e
41+
x = y;
42+
rd = sqrt(exp(x))
43+

ICE02.doc

41 KB
Binary file not shown.

ICE02.m

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
% -----------------------------------------
2+
% HW1
3+
% LiXin
4+
% 2022/2/28
5+
% -----------------------------------------
6+
close all; clear all; clc;
7+
8+
%% Input for Problem 1~5
9+
10+
% Problem 1
11+
M = [1 2; 3 4];
12+
even_index(M)
13+
14+
% Problem 2
15+
v = [1 2 3 4];
16+
flip_it(v)
17+
18+
% Problem 3
19+
N = magic(5);
20+
n = 2;
21+
top_right(N, n);
22+
23+
% Problem 4
24+
A = magic(5);
25+
peri_sum(A)
26+
27+
% Problem 5
28+
cal(pi/2)
29+
30+
%% Problem 6
31+
h = 2;
32+
v = sqrt(2 * 9.8 *h);
33+
for i = 1:8 % rebound 8 times
34+
v = 0.85 * v;
35+
end
36+
h = v*v/(2*9.8)
37+
38+
%% Problem 7
39+
n=1;
40+
T=300;
41+
R=0.08206;
42+
a=1.39;
43+
b=0.039;
44+
V=linspace(0.08,6,100);
45+
P1=n*R*T./V;
46+
P2=n*R*T./(V-n*b)-n*n*a./V.^2;
47+
plot(V,P1)
48+
hold on
49+
plot(V,P2)
50+
51+
%% Problem 8
52+
53+
% a
54+
x = 10 * rand(ceil(10*rand)+2,1)
55+
% b
56+
mysum=0;
57+
for i = 1:size(x,1)
58+
mysum = mysum + x(i,1);
59+
end
60+
mysum
61+
% c
62+
if mysum == sum(x)
63+
disp('Congratulations!! you did it right')
64+
load handel;
65+
sound(y, Fs)
66+
else
67+
fprintf('Sorry, %.2f ~= %.2f. Please try again.\n', mysum, sum(x))
68+
end
69+
% d
70+
x = 10 * rand(ceil(10*rand)+2,1);
71+
mysum=0;
72+
i = 1;
73+
while i <= size(x,1)
74+
mysum = mysum + x(i,1);
75+
i = i + 1;
76+
end
77+
mysum
78+
if mysum == sum(x)
79+
disp('Congratulations!! you did it right')
80+
load handel;
81+
sound(y, Fs)
82+
else
83+
fprintf('Sorry, %.2f ~= %.2f. Please try again.\n', mysum, sum(x))
84+
end
85+
86+
87+
%% Problem 1
88+
% returns a matrix that contains only those elements of M that are in
89+
% even rows and columns
90+
function res = even_index(M) % M as a matrix
91+
res = M(2:2:end, 2:2:end);
92+
end
93+
94+
%% Problem 2
95+
% returns the opposite order of v
96+
function w = flip_it(v) % row vector v, row vector w
97+
for i = size(v,2) : -1 : 1
98+
w(1,size(v,2) - i + 1) = v(1,i);
99+
end
100+
end
101+
102+
%% Problem 3
103+
% returns the n-by-n square subarray of N located at the top right corner
104+
% of N
105+
function M = top_right(N, n) % a matrix N, a scalar non-negative integer n
106+
M = N(1:n, end-n+1:end)
107+
end
108+
109+
%% Problem 4
110+
% add together the elements that are in the first and last rows and columns
111+
function my_sum = peri_sum(A)
112+
my_sum = 0;
113+
my_sum = my_sum + sum(A(:,1)) + sum(A(:,end)) + sum(A(1,:)) + sum(A(end,:));
114+
my_sum = my_sum - A(1,1) - A(1,end) - A(end, end) - A(end,1);
115+
end
116+
117+
%% Problem 5
118+
% power series for sin(x), 5 terms are needed, when i exceeds 20, the loop
119+
% terminates
120+
function sin_x = cal(x)
121+
sin_x = 0;
122+
for i = [1:2:20]
123+
sin_x = sin_x + (-1)^floor(i/2)*x^i/factorial(i);
124+
sin(x)-sin_x
125+
end
126+
end

ICE02.pdf

28.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)