Itc Mathlab TP
Itc Mathlab TP
Subject: MATLAB
Group 6: I3-GCI-A2
ENG Samrithvongkheang ID: e20200406
HAKKA Kimheng ID: e20200002
HAM Chetra ID: e20200546
HAY Liheng ID: e20200825
HEAL Na Bunnin ID: e20201203
HEAN Sopha ID: e20200085
Introduction 1
References 31
Appendix B TP instruction 34
Script Listings
1 TP1EX12.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 TP1EX13A.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 TP1EX14.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 TP1EX15i.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 TP1EX15ii.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
6 TP1EX21.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7 TP1EX22.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
8 TP1EX24.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
9 TP1EX31D.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
10 TP1EX31F.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
11 TP1EX31G.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
12 TP1EX32.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
13 kmh2ms.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
14 ms2kmh.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
15 polaire.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
16 TP1EX43.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
17 TP2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
18 TP2_Program.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
19 Results for case 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
20 Results for case 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
21 Results for case 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
22 TP2_Analyze.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
List of Figures
1 s1 in function of Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 Addition of s2 and s3 to figure 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Addition of Formatting to figure 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Addition of point of t in figure 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Displaying s1 , s2 and s3 in 3 separate graphs . . . . . . . . . . . . . . . . . . . . . . . . 15
6 Addition of graph x(t) to figure 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7 3D surface of z1 and z2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8 OA1 A2 in polar coordinate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
9 Beam subjected to a distributed load. . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
10 The divided segment for calculating shear force and bending moment. . . . . . . . . . . 21
11 Diagrams of V (x) and M(x) for case 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 27
12 Diagrams of V (x) and M(x) for case 2 . . . . . . . . . . . . . . . . . . . . . . . . . . 28
13 Diagrams of V (x) and M(x) for case 3 . . . . . . . . . . . . . . . . . . . . . . . . . . 29
14 Diagrams of V (x) and M(x) for all cases . . . . . . . . . . . . . . . . . . . . . . . . . 30
List of Tables
1 Extreme value of V (x), N(x) and σx for all cases . . . . . . . . . . . . . . . . . . . . . 30
2 xVM_table1.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3 xVM_table2.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4 xVM_table3.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Institute of Technology of Cambodia MATLAB (TP) Dr. Keang Sè POUV
Introduction
In this practical work (TP)1 , we focused on getting start with MATLAB. There are exercises indicated
to some needed and common commands and functions in civil engineering such as:
• Manipulation of matrices
• Graphics functions
• Writing functions.
What is MATLAB?
Like other well-known programming languages including Java, C#, etc., MATLAB was initially known
as the matrix programming language created by MathWorks. MATLAB is an acronym for "Matrix
Laboratory", it provides an interactive environment with hundreds of built-in functions for technical
computing, graphics, and animations.
Operating modes
1. interactive mode: MATLAB executes the instructions as they are given (Conmmend Window).
2. executive mode: MATLAB executes line by line an ".m" file (MATLAB programming language)
(write in Script).
Advantages
• Easy to use, quick to learn
• Possibility of interfacing it with other languages (C, C++, Fortran), enables parallel computing.
Disadvantages
• Limitation in memory
• Paid to use.
1
Please refer to Appendix B for the instruction and exercises.
y1 =
>> y2 = cos(x)
y2 =
Then calculate y3 = 3 tan2 (x) and y4 = sin(2x) + cos(3x) using exclusively the previous vectors y1
and y2 .
We have 2
sin x y1
tan x = =⇒ y3 = 3
cos x y2
sin(2x) = 2 sin x cos x and cos(3x) = 4 cos3 x − 3 cos x
=⇒ y4 = (2y1 y2 ) + (4y23 − 3y2 )
Command Window:
>> y3 = 3.*(y1./y2).^2
y3 =
>> y4 = (2.*y1.*y2)+(4.*y2.^3-3.*y2)
y4 =
Listing 1: TP1EX12.m
syms x ; % Making x as a variable by command syms
Command Window:
1/3
sqrt(2) exp(- x )
1/3
sqrt(2) exp(- x )
- -------------------
2/3
3 x
We get
√ √3
√ √
3
I = −3 2e − x 2 3 x + x 2 + 2 + c
√ −√ 3
2e x
d =− √ 3
3 x2
3. We consider the following vectors:
0 −5 −1
u = −6 , v = 2 and w = 0
3 1 1
(a) Calculate t = u + 3uv − uv w .
Listing 2: TP1EX13A.m
1 u = [0; -6; 3];
2 v = [-5; 2; 1];
3 w = [-1; 0; 1];
4 t = u + 3*u.*v - u.*v.*w
Command Window:
>> t =
0
-42
9
We get
0
t = −42
9
ans =
6.7082
>> norm(v)
ans =
5.4772
>> norm(w)
ans =
1.4142
>> norm(t)
ans =
42.9535
We get
∥u∥ = 6.7082, ∥v ∥ = 5.4772, ∥w ∥ = 1.4142 and ∥t∥ = 42.9535
Listing 3: TP1EX14.m
1 n=100;
2 a=[i, -i];
3 for m=1:n
4 a=[a, m+m*i, m-m*i];
5 end
6 a
Command Window:
>> a
a =
1.0e+02 *
Columns 1 through 4
Columns 5 through 8
ans =
Columns 1 through 5
Columns 6 through 10
141.42 141.42
i. Command prod
• Let n be the factorial number
• Defining a vector contain 1, 2, 3, . . . , n
Listing 4: TP1EX15i.m
1 n = 100;
2 v = 1:n;
3 f = prod(v)
Command Window:
>> f =
9.3326e+157
f =
f =
f =
Listing 5: TP1EX15ii.m
1 fprintf('Factorial Calculation \n')
2 n = input('Please insert a number: ');
3 f = 1;
4 for m = 1:n
5 f = f*m;
6 end
7 formatSpec='The result is: %g! = %g \n';
8 fprintf(formatSpec,n,f)
Note: fprintf to display the text, input to input the wanted value of n, formatSpec to
formats data, %g for compact of number with no trailing zeros.
Command Window:
Factorial Calculation
Please insert a number: 100
The result is: 100! = 9.33262e+157
Listing 6: TP1EX21.m
1 U = [-1:-1:-15];
2 [m,n] = size(U)
3 V = [U(:,[1:5]), U(:,[end-4:end])]
4 W = -1/2.*U
5 X = 1./U.^2
6 P = 2*W.^2.*X
Command Window:
m =
n =
15
V =
W =
Columns 1 through 8
Columns 9 through 15
X =
Columns 1 through 8
Columns 9 through 15
P =
Columns 1 through 8
Columns 9 through 15
1 2 3 4 5 6 7 8 9 10
2. Define matrix M = 11 12 13 14 15 16 17 18 19 20. What are its dimensions m ×
21 22 23 24 25 26 27 28 29 30
1 2
3 7
n? Extract from this matrix, the matrix N = 11 12 , and the matrix P =
. Extract
23 27
21 22
from matrix M, the matrix Q obtained by taking in matrix M one column out of 2.
Listing 7: TP1EX22.m
1 M=[[1:1:10]; [11:1:20]; [21:1:30]];
2 [m,n]=size(M)
3 N=M(:,[1,2])
4 P=M([1,3],[3,7])
5 Q=M(:,[1:2:end])
Command Window:
m =
n =
10
N =
1 2
11 12
21 22
P =
3 7
23 27
Q =
1 3 5 7 9
11 13 15 17 19
21 23 25 27 29
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
B =
How many numbers in this matrix B are between 0.4 and 0.8? Where are they located?
Command Window:
>> Locate = find(B>0.4 & B<0.8)
Locate =
3
6
7
10
14
Count =
C =
1 0 0 1
0 0 0 0
0 0 0 1
0 1 1 0
4. Solve the linear equation system below using two possible approaches:
x + y = 14 (1)
y + z = 10 (2)
x −y =4 (3)
z −t =1 (4)
i. Manually
Taking
(1) + (3) =⇒ 2x = 18 =⇒ x = 9
(1) =⇒ y = 14 − x = 5
(2) =⇒ z = 10 − y = 5
(4) =⇒ t = z − 1 = 4
• Put the equations and the variables together (optional, we can also write all of them in
the command solve)
• Solve
• Show the result.
Listing 8: TP1EX24.m
1 clear x y z t
2 syms x y z t
3 Eq1 = x+y==14;
4 Eq2 = y+z==10;
5 Eq3 = x-y==4;
6 Eq4 = z-t==1;
7 Eqs = [Eq1, Eq2, Eq3, Eq4];
8 Vars = [x y z t];
9 Sol = solve(Eqs, Vars);
10 x=Sol.x
11 y=Sol.y
12 z=Sol.z
13 t=Sol.t
Command Window:
x =
y =
z =
t =
t =
0 1 2 3 4 5 6 7 8 9 10
(c) Create two other signals defined by s2 (t) = 1 − e −2t and s3 (t) = 1 − e −4t , then display them
in the same figure.
Using command hold on so that we can display maltiple graph in the same figure.
Command Window:
>> hold on
>> s2=1-exp(-2*t);
>> plot(t,s2)
>> s3=1-exp(-4*t);
>> plot(t,s3)
(d) Make changes to display these 3 signals in blue, red and green respectively. In addition to the
colors, show asterisks (*), crosses and dots at different values making up the 3 signals. Add
a legend to the curves and the titles corresponding to the abscissa axis and the ordinate axis.
Listing 9: TP1EX31D.m
1 t=linspace(0,10,11);
2 s1=1-exp(-t);
3 plot(t,s1,'b*-')
4 hold on
5 s2=1-exp(-2*t);
6 plot(t,s2,'rx:')
7 s3=1-exp(-4*t);
8 plot(t,s3,'g.-.')
9 title('Signal in function of time s(t)')
10 ylabel('Signal s_1, s_2, s_3')
11 xlabel('t (Time in second)')
12 legend('s_1','s_2','s_3')
(e) We now want to change the time variable and define it with 10 times more points.
Making the only change [t=linspace(1,10,11*10)], then just run the script (listings 9)
again.
(f) Display these 3 signals in the same figure, but this time in 3 separate charts on two lines,
including 2 charts at the top and 1 chart at the bottom.
Graphics 1 Graphics 2
Graphics 3
Using subplot(m,n,p) divides the figure into m × n grid and grid position specified by p.
(g) Now add in the third graph the harmonic curve of form x(t) = A cos(ωt +φ) with ω = 2, A = 3
and φ = 0.5. Display the properties of this curve like title, color, etc.
In the script, using command hold on after plotting s3 (t), then add the codes for displaying
x(t) and makeing some changes to the properties.
Script: continue from listings 10
2. 3D graphics
Illustrate in the same graph, the surfaces of the following two functions:
• z2 = x − y + 50
First, we defined the vectors in the functions (x and y ) to create some points for plotting by
-10:0.25:10. Then, using meshgrid to produce full grids from vectors (Otherwise 3D ploting
wouldn’t work). Third, we defined our function (r, z1 , z2 ). Next, displaying z1 in 3D by command
surf; then, using command hold on so that we can display z2 in the same figure. Finally, we
added the properties.
• name: Name of the function, and it must be the same as the file’s name.
• inputArg1 & 2: The variables that we want to compute.
• outputArg1 & 2: The variables that we want to return.
• Since 1km/h = 1000/3600m/s, we can write our function as:
• Then, save and run it. However; it returned as error. In order to compute, we must define
the variables and call this function (by name) in the Command Window.
Command Window:
>> kmh=120;
>> [ms]=kmh2ms(kmh)
ms =
33.3333
Command Window
>> ms2kmh
Not enough input arguments.
>> kmh=ms2kmh(3)
kmh =
10.8000
3. Write a function named polai r e, taking the Cartesian coordinates (x, y ) as input arguments of a
point and returning the polar coordinates (r, θ) as output from this point, where θ is in degrees.
Using this created polai r e function, then write a new script (file extension .m) to:
(a) Convert the Cartesian coordinates of A1 (43.3, 25) and A2 (65.78, 23.94) to polar coordinates.
(b) Illustrate graphically the triangle OA1 A2 in polar coordinates, where O(0, 0) is the coordinate
system of the polar axes.
−−→ −−→
(c) Determine the angle α formed by the two vectors OA1 and OA2 .
Command Window
r1 =
49.9989
theta1 =
30.0007
r2 =
70.0009
theta2 =
19.9985
Alpha =
10.0022
B(A + 21 B)w
=⇒ R1,y = − + Bw
L
−(A + 21 B)Bw + LBw
=
L
Bw (−A − 21 B + L)
=
L
Bw (L − A − 12 B) (A + 21 B)Bw
Therefore, R1 = and R2 = .
L L
Figure 10: The divided segment for calculating shear force and bending moment.
• shear force (V )
=⇒ M = V x = R1 x
=⇒ M = R1 x − w B(x − A − B/2)
− plot V (x) and M(x) diagrams, then indicate the Vmin , Vmax and Mmax values in the positions corre-
sponding with curves.
− save the results of each case in a file in “.txt” by column x, V and M respectively.
56 end
57
58 %plot
59 %putting litle to the figure
60 sgtitle("Diagram of Shear Force and Bending Moment Case #"+c, ...
61 'FontName','Times New Roman', ...
62 'FontWeight','bold','FontAngle','italic','FontSize',16)
63
64 subplot(2,1,1)
65 x = [x1 x2 x3];
66 %Because V1 and V3 are single value, we need to make it into vector corresponding
with x, so V and x contain the same size.
67 V = [ones(size(x1))*V1 V2 ones(size(x3))*V3];
68 plot(x,V,'b','LineWidth',2)
69 %Keeping extra space on the graph
70 xlim([-1 x(end)+1])
71 ylim([Vmin-30 Vmax+30])
72 %Showing grid
73 grid on
74 xticks(0:x(end))
75 yticks(Vmin:20:Vmax)
76 %Adding title and label
77 title('Shear Force','FontSize',14,'FontName','Times New Roman')
78 xlabel('x (in m)','FontSize',13,'FontName','Times New Roman')
79 ylabel('V(x) (in kN)','FontSize',13,'FontName','Times New Roman')
80 %Putting text
81 nVmax = find(V==Vmax); %Locate the position of the value
82 nVmin = find(V==Vmin);
83 text(x(nVmax(end))-.25,Vmax+10,"V_{max} = "+Vmax,'FontName','Times New Roman')
84 text(x(nVmin(1))-.25,Vmin-10,"V_{min} = "+Vmin,'FontName','Times New Roman')
85
86 subplot(2,1,2)
87 M = [M1 M2 M3];
88 plot(x,M,'r','LineWidth',2)
89 xlim([-1 x(end)+1])
90 ylim([0 Mmax+30])
91 grid on
92 xticks(0:x(end))
93 yticks(0:20:100)
94 title('Bending Moment','FontSize',14,'FontName','Times New Roman')
95 xlabel('x (in m)','FontSize',13,'FontName','Times New Roman')
96 ylabel('M(x) (in kN.m)','FontSize',13,'FontName','Times New Roman')
97 nMmax = find(M==Mmax);
98 text(x(nMmax)-.5, Mmax+10,"M_{max} = "+Mmax,'FontName','Times New Roman')
99
100 %create table and write file
101 table = [x; V; M]; % We have data 3 row defining x, V and M respectively
102 fid = fopen("xVM_table"+c+".txt",'w'); %Just for the name to be loaded automatically
103 fprintf(fid,'%4.1f %4.3f %4.3f\n',table);
104 % the data is written by column 3 times then enter to make it a vertical table
105 fclose(fid);
Note:
+ Lines 33 and 37, for the value of x, adding the first value of x2 and x3 (A+0.1 and A+B+0.1) for
it not to repeat the same value when we combine x1, x2 and x3, because the former sigments (x1
and x2) end in A and A + B respectively already.
+ Lines 60, 85, 86, 100 and 104, Double quotes ("") and (+) are used for string operation.2
+ Line 67, in order to plot, we need V and x to be vectors that contain the same numbers. Since,
V 1 and V 2 are single value (lines 30 and 38), in order to make it corresponding to x automatically:
+ Lines 81-84, we want the text of Vmax and Vmin to position automatically. Thus we need V to be
the same term as x:
+ Lines 103-108, fprintf(FID, FORMAT, A, ...) applies the FORMAT to all elements of array A
and any additional array arguments in column order, and writes the data to a text file.3
• Case 1:
Command Window:
Results:
Case #1
a = 0.2m, b = 0.4m, L = 6m, A = 0m, B = 6m, w = 20kN/m, Sigma_a = 28MPa
Moment inertia: Iz = 0.00106667 m4
Reactions of the two supports:
R1 = 60 kN and R2 = 60 kN
Maximum shear stress: V = 60 kN
Maximum bending moment: M = 90 kN.m
Maximum bending stress: Sigma_x = 16.875 MPa
maximum stress <= allowable stress, VERIFIED!
2
For more operators: [» help string]
3
Its form taken from an example of: [» help fprintf]
• Case 2:
Command Window:
Results:
Case #2
a = 0.2m, b = 0.4m, L = 6m, A = 1m, B = 4m, w = 20kN/m, Sigma_a = 28MPa
Moment inertia: Iz = 0.00106667 m4
Reactions of the two supports:
R1 = 40 kN and R2 = 40 kN
Maximum shear stress: V = 40 kN
Maximum bending moment: M = 80 kN.m
Maximum bending stress: Sigma_x = 15 MPa
maximum stress <= allowable stress, VERIFIED!
• Case 3:
Command Window:
Results:
Case #3
a = 0.2m, b = 0.4m, L = 6m, A = 2m, B = 2m, w = 20kN/m, Sigma_a = 28MPa
Moment inertia: Iz = 0.00106667 m4
Reactions of the two supports:
R1 = 20 kN and R2 = 20 kN
Maximum shear stress: V = 20 kN
Maximum bending moment: M = 50 kN.m
Maximum bending stress: Sigma_x = 9.375 MPa
maximum stress <= allowable stress, VERIFIED!
Finally, we want to compare and analyze the results of the 3 case studies:
− draw the V(x) and M(x) diagrams for the 3 cases using only the previously saved .txt files.
− make a summary table of the extreme values of V, M and of σx between the 3 cases to compare.
Note:
+ Lines 5-7, our .txt file contains three columns of integers, and [A,COUNT] = fscanf(FID,FORMAT)
reads and converts data from a text file into array A in column order.4
+ So, we specified to read as integers (%f), and create a 3 rows matrix ([3,inf]) for each row
containing x, V and M respectively.
4
its form is taken directly from an example of: [» help fscanf].
References
[1] K.S. POUV, 2015, MATLAB course book, Institute of Technology of Cambodia, Phnom Penh.
[4] MATLAB Documentation, MathWorks® Help Center, www.mathworks.com, accessed 14 June 2023,
<https://www.mathworks.com/help/matlab/index.html?s_tid=hc_panel>.
Appendix
Table 2: xVM_table1.txt
0.0 60.000 0.000 1.3 34.000 61.100 2.6 8.000 88.400 3.9 -18.000 81.900 5.2 -44.000 41.600
0.1 58.000 5.900 1.4 32.000 64.400 2.7 6.000 89.100 4.0 -20.000 80.000 5.3 -46.000 37.100
0.2 56.000 11.600 1.5 30.000 67.500 2.8 4.000 89.600 4.1 -22.000 77.900 5.4 -48.000 32.400
0.3 54.000 17.100 1.6 28.000 70.400 2.9 2.000 89.900 4.2 -24.000 75.600 5.5 -50.000 27.500
0.4 52.000 22.400 1.7 26.000 73.100 3.0 -0.000 90.000 4.3 -26.000 73.100 5.6 -52.000 22.400
0.5 50.000 27.500 1.8 24.000 75.600 3.1 -2.000 89.900 4.4 -28.000 70.400 5.7 -54.000 17.100
0.6 48.000 32.400 1.9 22.000 77.900 3.2 -4.000 89.600 4.5 -30.000 67.500 5.8 -56.000 11.600
0.7 46.000 37.100 2.0 20.000 80.000 3.3 -6.000 89.100 4.6 -32.000 64.400 5.9 -58.000 5.900
0.8 44.000 41.600 2.1 18.000 81.900 3.4 -8.000 88.400 4.7 -34.000 61.100 6.0 -60.000 0.000
0.9 42.000 45.900 2.2 16.000 83.600 3.5 -10.000 87.500 4.8 -36.000 57.600
1.0 40.000 50.000 2.3 14.000 85.100 3.6 -12.000 86.400 4.9 -38.000 53.900
1.1 38.000 53.900 2.4 12.000 86.400 3.7 -14.000 85.100 5.0 -40.000 50.000
1.2 36.000 57.600 2.5 10.000 87.500 3.8 -16.000 83.600 5.1 -42.000 45.900
Table 3: xVM_table2.txt
0.0 40.000 0.000 1.3 34.000 51.100 2.6 8.000 78.400 3.9 -18.000 71.900 5.2 -40.000 32.000
0.1 40.000 4.000 1.4 32.000 54.400 2.7 6.000 79.100 4.0 -20.000 70.000 5.3 -40.000 28.000
0.2 40.000 8.000 1.5 30.000 57.500 2.8 4.000 79.600 4.1 -22.000 67.900 5.4 -40.000 24.000
0.3 40.000 12.000 1.6 28.000 60.400 2.9 2.000 79.900 4.2 -24.000 65.600 5.5 -40.000 20.000
0.4 40.000 16.000 1.7 26.000 63.100 3.0 0.000 80.000 4.3 -26.000 63.100 5.6 -40.000 16.000
0.5 40.000 20.000 1.8 24.000 65.600 3.1 -2.000 79.900 4.4 -28.000 60.400 5.7 -40.000 12.000
0.6 40.000 24.000 1.9 22.000 67.900 3.2 -4.000 79.600 4.5 -30.000 57.500 5.8 -40.000 8.000
0.7 40.000 28.000 2.0 20.000 70.000 3.3 -6.000 79.100 4.6 -32.000 54.400 5.9 -40.000 4.000
0.8 40.000 32.000 2.1 18.000 71.900 3.4 -8.000 78.400 4.7 -34.000 51.100 6.0 -40.000 0.000
0.9 40.000 36.000 2.2 16.000 73.600 3.5 -10.000 77.500 4.8 -36.000 47.600
1.0 40.000 40.000 2.3 14.000 75.100 3.6 -12.000 76.400 4.9 -38.000 43.900
1.1 38.000 43.900 2.4 12.000 76.400 3.7 -14.000 75.100 5.0 -40.000 40.000
1.2 36.000 47.600 2.5 10.000 77.500 3.8 -16.000 73.600 5.1 -40.000 36.000
Table 4: xVM_table3.txt
0.0 40.000 0.000 1.3 34.000 51.100 2.6 8.000 78.400 3.9 -18.000 71.900 5.2 -40.000 32.000
0.1 40.000 4.000 1.4 32.000 54.400 2.7 6.000 79.100 4.0 -20.000 70.000 5.3 -40.000 28.000
0.2 40.000 8.000 1.5 30.000 57.500 2.8 4.000 79.600 4.1 -22.000 67.900 5.4 -40.000 24.000
0.3 40.000 12.000 1.6 28.000 60.400 2.9 2.000 79.900 4.2 -24.000 65.600 5.5 -40.000 20.000
0.4 40.000 16.000 1.7 26.000 63.100 3.0 0.000 80.000 4.3 -26.000 63.100 5.6 -40.000 16.000
0.5 40.000 20.000 1.8 24.000 65.600 3.1 -2.000 79.900 4.4 -28.000 60.400 5.7 -40.000 12.000
0.6 40.000 24.000 1.9 22.000 67.900 3.2 -4.000 79.600 4.5 -30.000 57.500 5.8 -40.000 8.000
0.7 40.000 28.000 2.0 20.000 70.000 3.3 -6.000 79.100 4.6 -32.000 54.400 5.9 -40.000 4.000
0.8 40.000 32.000 2.1 18.000 71.900 3.4 -8.000 78.400 4.7 -34.000 51.100 6.0 -40.000 0.000
0.9 40.000 36.000 2.2 16.000 73.600 3.5 -10.000 77.500 4.8 -36.000 47.600
1.0 40.000 40.000 2.3 14.000 75.100 3.6 -12.000 76.400 4.9 -38.000 43.900
1.1 38.000 43.900 2.4 12.000 76.400 3.7 -14.000 75.100 5.0 -40.000 40.000
1.2 36.000 47.600 2.5 10.000 77.500 3.8 -16.000 73.600 5.1 -40.000 36.000
B TP instruction
TRAVAUX PRATIQUES
D’INITIATION À MATLAB III
Dr.–Ing. K.S. POUV
Pour
I3 GCI et I3 OAC
CONSEILS :
Chaque compte-rendu doit contenir les scripts et les résultats clés de compilation ainsi que
les commentaires. Les comptes-rendus peuvent également être rédigés pendant les séances
de TP.
Dr.–Ing. K.S.POUV 2
TP 1
Prise en main de Matlab
Exercice 1 : Vecteurs, courbes et calculs formels
1. Définir la variable x = , , et calculer y1=sin(x) et y2=cos(x). Calculer ensuite
6 4 3
2
y3=3tan (x) et y4=sin(2x)+cos(3x) en utilisant exclusivement les vecteurs y1 et y2
précédents.
2. On a . Calculer :
, et
a. Calculer t=u+3uv-uvw.
b. Calculer u , v , w ,||t||.
4. Définir la variable complexe a=[i, -i, 1+i, 1-i, 2+2i, 2-2i, …., 100+100i, 100-1ooi]. Puis calculer
le module complexe de chaque élément de a.
5. Calculer la factorielle de 100 (i.e., 100 !) par deux méthodes possibles. On peut essayer
d'utiliser par exemple : (1) la commande « cumprod » et (2) la commande « for ».
Dr.–Ing. K.S.POUV 3
Exercice 3 : Fonctions graphiques
1. Graphiques 2D :
a. Créer un vecteur temps t (t en secondes) allant de 0 à 10 avec 11 points.
b. Créer un signal s1(t) = 1 – e-t puis l’afficher en fonction du temps.
c. Créer deux autres signaux définis par s2(t) = 1 – e-2t et s3(t) = 1 – e-4t, puis les afficher
dans la même figure.
d. Faire les modifications pour afficher ces 3 signaux respectivement en bleu, en rouge
et en vert. Faire apparaître en plus des couleurs des astérisques (*), des croix et des
points aux différentes valeurs constituant les 3 signaux. Ajouter une légende à vos
courbes et les titres correspondant à l’axe d’abscisse et l’axe d’ordonnée.
e. On souhaite maintenant changer la variable temporelle et la définir avec 10 fois plus
de points. Faire les modifications nécessaires.
f. Afficher ces trois signaux dans une même figure, mais cette fois-ci dans 3 graphiques
séparés sur deux lignes, dont 2 graphiques en haut et 1 graphique en bas (figure 0).
Les propriétés des courbes sont les mêmes que celles du premier cas.
Graphique 1 Graphique 2
Graphique 3
Figure 0. Format de l’illustration pour la question f.
g. Ajouter maintenant dans le troisième graphique la courbe harmonique de forme
x(t ) = A cos(t + ) avec ω = 2, A = 3 et φ=0.5. Faire apparaître les propriétés de cette
courbe comme le titre, le couleur, etc.
2. Graphiques 3D :
Illustrer, dans un même graphique, les surfaces des deux fonctions suivantes :
- z1 = 100sin(r)/r, where r = x 2 + y 2 (chapeau Mexicain)
- z2 = x – y + 50
Mettre également les titres pour les trois axes.
Dr.–Ing. K.S.POUV 4
TP 2
Mini-projet : Efforts internes d’une poutre sur appuis
simples
Dr.–Ing. K.S.POUV 5
de la figure. En bref, illustrez vos figures de telle manière qu’elles sont bien agréables à lire :
couleur de la courbe, épaisseur de la courbe, noms des deux axes, légendes, titre, etc. (voir
les exemples sur la figure 2).
(a)
(b)
Figure 2. Exemple des illustrations agréables à lire : (a) une courbe, et (b) plusieurs courbes.
Dr.–Ing. K.S.POUV 6