0% found this document useful (0 votes)
2 views20 pages

Outline Lesson 2

The document outlines the functionalities and applications of MATLAB in automotive engineering, detailing its mathematical processing capabilities, including matrix operations and various engineering problem-solving tools. It covers the interface, data processing methods, and specific functions for creating and manipulating arrays, as well as solving equations. Additionally, it discusses conventional mathematical operations and useful functions for array manipulation within MATLAB.

Uploaded by

dangvuduy42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Outline Lesson 2

The document outlines the functionalities and applications of MATLAB in automotive engineering, detailing its mathematical processing capabilities, including matrix operations and various engineering problem-solving tools. It covers the interface, data processing methods, and specific functions for creating and manipulating arrays, as well as solving equations. Additionally, it discusses conventional mathematical operations and useful functions for array manipulation within MATLAB.

Uploaded by

dangvuduy42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Outline Lesson 2 – Matlab and its application in automotive engineering

1. About Matlab
1.1. Matlab
MATLAB is an application software of Mathworks Corporation (USA). This is a very
powerful mathematical processing software, through the implementation of mathematical
operations on the matrix (MAT - Matrix), which is programmed by mathematical and
computer experts to solve the algorithms through mathematical processing tool libraries
(LAB - Laboratory). The software also provides many different modules, serving specific
fields and specialties.
The purpose of Matlab software is for researchers, designers, and programmers
1.2. Scope of application
Matlab serves as a powerful computational tool that allows you to quickly calculate the
value of a complex expression and store the value of the expression in the computer's
memory
Malab provides tools for processing arrays of data: vectors and matrices, allowing the
calculation of the results of expressions with vector input data
Matlab provides functions to solve common engineering problems such as:
 Processing polynomials (multiplying, dividing, finding the 0 point (solution) of
polynomials).
 Solve general equations.
 Solving Linear Equations
 Solving Differential Equations
 Processing measurement signals with fast furier implementation
 Interpolation operations for processing data in tables
 Optimal Problem Solving
 Differential Integral
 Graphic Tools
Matlab provides programming tools for building application programs
There are also separate application modules for in-depth research such as
 Solving Differential Equations of Specific Functions for Solving Persistent
Problems
 Simulink allows simulation of machine structures
 Stateflow: for the study of gas or liquid flows
 Fuzzy logic: the study of fuzzy logic
1.3. Interface of Matlab
1.3.1. Interface

On the main interface window there are several work areas, as well as some smaller
windows:
 Toolbar: contains icons that perform a number of normal (Open, New, Save, Cut,
Paste...) and separate functions (Simulink, Guide, Help...).
 Command window: This is the most important window, which can allow you to
perform math operations, or link to other windows.
 Some sub-windows perform their own functions (notification of the current
directory, through executed command lines, existing variable names,...)
1.3.2. How to write expressions, use variables, function keys
a. Calculate numeric expressions:
 Number expressions can be typed directly into the Matlab command window, after
pressing Enter the result of the expression will appear on the screen
 Calculations: Addition +, Subtraction -, Multiplication *, Division/, Power ^ and
calculation priority brackets
 Long command lines can be split into multiple lines (by pressing Enter), but at the
end of each line (except the last line) we must add a comma...
b. Use functions, constants, and variables
 Các hàm: sqrt, sin, cos, tan, cot, sind, cosd, exp, log, log10, asin, acos, atan, acot
 Defined constants: eps, realmax, realmin, pi, inf
 When writing an expression, the calculation result is stored in a sea with the
default name ans.
 Normally, to save the calculation result, we usually use the following syntax
assignment:
<variable name> = <expression>
or <variable name> = <expression>;
In which:
 Variable names are set by the user, with no spaces and are case-sensitive, bonus.
 in syntax 1: the result of the calculation of the expression will appear on the
screen and stored under the variable name,
 in syntax 2: the result does not appear on the screen
 To check the current value of the variable we just need to type the name of the
variable
 In an expression instead of entering a specific value, we can type the name of the
variable
 To check the variables that exist in the Matlab environment we type whos, or whos
 To remove the sea from the field, we can use the following commands:
 clear, clear <variable name1>, <variable name2>...
c. Function keys
 To edit the command lines we use the arrow keys or use the collage function
 Backward deletion key, del key, end, pageup, pagedown...
 Other common keyboard shortcuts like in application software in Windows:
Ctrl+C, Ctrl+N, Ctrl+O, Ctrl+X,...
Note – Search for functions in the software library: F1 –
Help For example:

2. Array (matrix) data processing in matlab


Some basic concepts:
- Number: is a matrix with a size of 1x1 (1 row, 1 column)
- Vector: is a matrix with the number of rows, or the number of columns equal to 1
 Row vector: matrix with rows equal to 1
 Column vector: matrix with column number equal to 1
- Matrix:
 Number matrix (number array): is a matrix of size mxn (m rows, n columns)
where the elements of the matrix are all numerical data.
 Block matrix (block array): is a matrix with character string data-type elements.
2.1. Methods of creating data arrays
2.1.1. Input method directly from the
keyboard General Principles
 Elements of the array are enclosed in square brackets:[ ]
 Elements on a row are separated by a space (blank step)
 Rows are separated by a ";" or an "Enter"
sign Example 1: If we type: C=[3.5 4.3 5.0]
"enter" , we will get a row vector with three
elements, 3.5, 4.3, and
5.0, and the Matlab screen will look like this:
Example 2: If we type: D=[3.5; 4.3; 5.0] "enter", we will get the row vector
and in Matlab it will look like this:
Example 3: Combined, we will get a vector with both rows and columns,
entering
E=[1 2 3; 4 5 6; 7 8 9] "enter", Matlab shows:
Note: The number of elements in each row must be the same
2.1.2. Use the operator " : "
Syntax:
<Variable Name>=<Begin>: <Step>: <Limit>
Will create a row vector with the first element being the value <Begin>, the increments
between the elements being <Step>, the last element value not exceeding <Limit>
Note: If the value of <Step> is ignored, the machine will receive increments = 1
Example: If you type after the command line prompt
Y=1:2:10
We receive the cargo vector:
If entered after the command-line
prompt: Y=1:9 . We get the vector:
2.1.3. Some other functions
a, Hàm zeros
Syntax: <Variable name>=zeros(<RowNum>, <ColumnNum)
Create a matrix with 0 elements, with a row number of <RowNum>, and a column
number of <ColumnNum>.
For example, the function M=zeros(2,3) will give the result:
b, Hàm ones
Syntax: <Variable name>=ones(<RowNum>, <ColumnNum)
Create a matrix with 1 elements, which have a row number of <RowNum>, and a column
number of <ColumnNum>.
Example 1: The function N=ones(3,4) will give the result:
VD2: Hàm N2=3.5*ones(2,4)

c, Jaw eye
Syntax: <Variable name>=eye(<RowNum>, <ColumnNum)
Or: <Variable name>=eye(<size>)
The first syntax will create a rectangular unit matrix, which is: the number of rows is
equal to <RowNum> and the number of columns is equal to <ColumnNum>.
The second syntax that creates the matrix has: number of rows = number of columns =
<size>
VD1: I=eye(3,4)
VD2: I2=eye(3)

d, Hàm diag
Application: Diagonal arrays commonly encountered in hardness matrices and mass
matrices in durability computing
Syntax: <variable name>=diag(v)
<variable name>=diag(v,n)
In which:
 v is a row vector, or column, or maybe a matrix
 If v is a vector, the function will result in a square matrix with elements on a fixed
diagonal that are molecules of the vector v
 If v is a matrix, the result is that the column vector of the elements is on the
diagonal of the matrix v
 n is the integer that indicates which diagonal STT of the matrix will place the
elements of the vector v (on the main line is the line 1,2,3,...; below the main line
is the line -1,-2,-3,...)
VD1: v=[1 3 5 3]; M=diag(v) will give the result:

Example 2: M=diag(v,2) will give the result:


(here the resulting diagonal is above the main
diagonal 2 units)
Example 3: M=diag(v,-3) will give the result:
(here the resulting diagonal is below the 3-unit
main diagonal)

VD4: v=[3 5 2; 2 3 5; 6 7 8]
A=diag(v)
The result will be:

2.2. Solving Equations with Matlab


Malab uses a row vector to define the coefficients of polynomials:
 The number of vector elements is equal to the order of the +1 polynomial (e.g. 3rd
order polynomials have 4 factors)
 The first element is the highest order coefficient of the polynomial
 Defective elements with a coefficient of 0
The value of a polynomial is determined by the polyval function: polyval(p,x)
For example: Determining the value of the polynomial P = X4 + 3X3 - 2X + 5 at point X
= 4.5, we use the following commands: p=[1 3 0 -2 5]; v=polyval(p,4.5)
- Some calculations on polynomials:
a. Solving higher-order algebraic equations
r = roots(c) : Gives the result that the vector r has elements that are the solution of the
polynomial C
b, The inverse function of roots is a poly function:
P=poly(r) : gives the coefficient vector of the solved polynomial which is the vector r.
c. Multiplication of polynomials:
w = conv(u,v) : Multiplied by 2 polynomials, if the number of elements of the vector
u is m, the number of elements of vector v is n, the vector w will have a length of n +m -1
d, Divide the two polynomials:
[q,r] = deconv(v,u) : The deconv function will perform the division of the
polynomial v for the polynomial u, the result obtained is 2 vectors: the vector q will
describe the resulting polynomial and the vector r describes the remainder of the division
For example: If u = [1 2 3 4] v = [10 20 30] The product of the two polynomials would
be: c = conv(u,v)
c = 10 40 100 160 170 120
If we use the polynomial division function, we get [q,r] = deconv(c,u)
q = 10 20 30
r=0000000
2.3. Calculations performed on the array
2.3.1. Conventional math
operations a, Addition
Syntax:
M = M1 + M2 + M3 + ...
Meaning: create a new array M of the same size as the array M1, M2, etc., the elements
of the new array are equal to the sum of each corresponding element of the component
arrays
Condition: M1, M2,.. arrays must be of the same size.
b, Subtraction
Syntax:
M = M1 - M2 - M3 - ...
Meaning: Create an M array with new array elements by each corresponding element of
the component arrays
Condition: M1, M2 arrays,... must be the same size.
c, Multiplication
Syntax:
M = A*B
Meaning: If A is a matrix of size (i x k) and B is a matrix of size (k x j), we get a matrix
M of size (i x j)
Condition: The number of columns of matrix A must be equal to the number of rows of
matrix B
d, Power of Power
Syntax:
M=A^n where: N is a positive
integer The result is n matrices A multiplied by each
other Condition: A must be a square matrix
e, Division of 2 matrices
Syntax:
M = A/B
Meaning: The matrix division is exactly the same as multiplication with the inverse
matrix:
M=A/B  M=A*B-1
Condition: Matrices A and B must be square matrices of the same size
2.3.2. Use operators with the " . "
+ Addition (without .+ operators)
– Except (no operator.-)
.* Multiply by element
./ Divide the elements
.^ Power of each element
‘ Transposition
Example 1: Defining the S vector, with the elements defined by the relation:
S=Y(i+1)-2*Y(i) with i=1 to n-1, Y=[3.5 5 6.5 7 8.5 9]
Here we use the vector expression:
Nhập: S=Y(2:end)-2*Y(1:end-1)
The results are as shown in the picture
below:
Example 2: Calculate the value of the V vector whose elements are determined by the
expression: V(i)=2*Y(i)-b, where Y =[3.5 6.2 7.0 5.4 6.2], b=1.5
Here we use the vector expression:
S=2*Y-b*ones(1,5)
The results are as shown in the picture
below:
VD3: S=Y(i+1)-E.*Y(i) with i=1 to n-1, Y= [1 2 3 2 1]
and E= [2 4 6 8]
Enter: S=Y(2:end)-2*Y(1:end-1) The result is as shown in the
following image:
Example 4: solving equations:
4X1 + 7X2 = 5
3X1 + 5X2 - 4X3 = 12
2X1 + 5X2 + X3 = 4
We create the matrices: M=[4 0 7; 3 5 -4; 2 5 1];
Y=[5; 12; 4] The solution of the system is defined by the expression:
X=eye(3,3)/M*Y hoặc X=M-1*N
2.3.3. Some functions used on arrays
a, Hàm size
Syntax: S=size(A) : gives a row vector that indicates the number of rows and
columns of the matrix
[r,c]=size(A) : assign the row number to r, the column number to c
For example: matrix M = [4 0 7; 3 5 -4; 2 5 1]
If we call the command: S=size(M), we get: S = 3 3
If we call the command: [x,y]=size(M), we get: x = 3 y = 3
b, Sum function
Syntax: sum(A)

If A is a vector, the function will return the result of the sum of the vector's elements
If A is a matrix, the function will return a row vector with elements that are the sum of the
elements of each column in matrix A
c, Hàm cumsum
Syntax: B = cumsum(A)
B = cumsum(A,dim)
Describe:
 If A is a vector, B = cumsum(A) will give the result that vector B has elements
that are the cumulative sum of the elements of vector A.
 If A is a matrix, cumsum(A) will give the result that the matrix is the same size as
A, and its elements are respectively the sum of the elements on each column of the
matrix A
 B = cumsum(A,dim) It will give the result that matrix B is the same size as A, the
elements of vector B will be the sum of the elements along the row or column of
matrix A, depending on the value of <dim>. For example, cumsum(A,1) will
calculate along the columns, cumsum(A,2) will calculate along the rows.
VD:
x=[1 2 3 4 5 ]; Y=cumsum(x) Result: Y = [1 3 6 10 15]
A = [1 2 3; 4 5 6]; B=cumsum(A) Result: B = 1 2 3
5 7 9
A = [1 2 3; 4 5 6]; C=cumsum(A,2) Result: C=1 3 6
4 9 15
f. Hàm diff
Syntax:
Y = diff(X) : Calculate the deviation between adjacent elements of the X
vector.
Y = diff(X,n) : Gives nth order deviation vector

Describe:
 If X is a vector, the result is a vector less than X 1 element:
[X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)]
 If X is a matrix, the diff(X) function gives the result of a column matrix of
deviations,
thus diff(X,2) gives the same result as diff(diff(X)).
VD: VD2:
x = [1 2 3 4 5]; y = diff(x)
Result: y = 1 1 1 1
z = diff(x,2)
Result: z = 0 0 0
3. Graphics in Matlab
3.1. Some graphing commands
Plot functions come in many forms, depending on the
input variables:
If Y is a vector, the PLOT(Y) function will print a
plot Y depending on its index in the vector
If X and Y are two vectors of the same magnitude of
the function PLOT(X,Y), the graph of the function
Y(X) will be printed
For example, to graph a Sine function with a
diaphragm value from 0 to 2 Pi, we use the following
command lines:
X=0:pi/100:2*pi; Y=sin(X); plot(X,Y)
If the argument in the function consists of multiple sets of X, Y, the function will
produce multiple graphs on the screen, and Matlab will automatically display the graphs
with different colors.
Example:
Nếu ta có: y1= sin(X); y2=sin(X-0.25); y3=sin(X-0.5)
The function: plot(x,y1,x, y2,x,y3) will give the graph
set as the drawing

In the plot function, we can also specify the line type, color, and marking style of the
node points with the syntax:
plot(x,y,'color_style_marker')
Where color_style_marker is a set of 1,2 or 3 characters separated by parentheses that
designate the line style, color, and marking style of the button points The letters of color
include: 'c', 'm', 'y', 'r', 'g', 'b', 'w', and 'k'. Corresponding to blue, young brick color,
yellow, red, blue, navy color, white and black.
Line style characters include '-' for streaks, '- -' for
dashes, ':' dotted lines, '-.' tiled lines, and 'none'
when no lines are drawn.
Characters for marking points include: '+', 'o', '*',
and 'x'.
For example, the plot statement(x,y,'y:+') plots a
graph as a yellow dotted line with a + mark
marking the node points.
Heed:
1. The plot command will automatically open a new graphics window. If this
window already exists, the default plot command will use this window. To open a
new window and bring it to date we use the figure command
figure(n) :where n is the number on the window's title bar
2. Draw a new curve to an existing
graph: The hold command allows a
curve to be added to an existing graph. If
you set hold on mode, Matlab will not
delete the existing graph and draw a new
curve when you call the drawing
command.
For example: hold on
plot(X,y1)
plot(X,y2)
plot(X,y3,'g-.')
3. Subplot function: divide the
graphic window into multiple parts to
display multiple graphs on one window
Where m,n,p are integers, it will divide the
graphic window into m rows and n columns and
bring the pth window to the present. The sub-
window index is defined from right to left and
from top to bottom.
subplot(1,3,1); plot(X,y1)
subplot(1,3,2); plot(X,y2)
subplot(1,3,3); plot(X,y3)
3.2. Annotations on graphs
A complete graph must always have the name and full annotations of the graph, here, we
use a few commands:
Syntax:
Title('Graph Name') : Export graph name
xlabel('x-axis name') : Export x-axis name
ylabel('y-axis name') : Exports the y-axis name
Grid on/off : Enable/disable grid lines on the graph
Legend('đ ồ_thị_1', đ ồ_thị_2', ' đ ồ_thị_3') : Annotations for different lines
4. Application of Matlab in Automotive Design Calculations
4.1. Application in automotive theoretical
calculations Give the input parameters as follows:
Number of engine revolutions: n min = 320, n max = 3200
Ratio of the number of hands: i1 = 54.03; i2 = 31.35; i3 = 18.2; i4 = 10.56; i5 = 6.13
Wheel Radius: Rbx = 0.432 (m)
Vehicle Gravity: G=82500(N)
Grip coefficient: f = 0.02
Air resistance coefficient Cw = 0.85
Front area: A = 4.3 m2
Gravitational acceleration: g = 10 m/s2
Maximum power Ne max = 81 (kW)
Some recipes to know:
- Calculate the traction force at the numerical arms:
M e .iti .t
Fki  rbx

+ In which:
2 3
 n n  n  
Ne  Ne max a e
b e
 c
e
  (kW)
  nN  nN   nN   
104 N
M e  (Nm) 1, 047n
e

With: The engine is a 4-stroke diesel engine, direct combustion chamber, so the
coefficients selected are: a= 0.5; b=1.5; c=1.
- Rolling resistance: Ff = G.f
- Air Resistance:
1
𝐹𝑤 𝜌𝐶 𝐴𝑣2
25,92 𝑤

CODE Matlab, determining the traction graph at the numerical arms:

n= 320:320:3200; % Rotation of the engine;

i1=54.03; i2=31.35; i3=18.2; i4=10.56; i5=6.13;% Ti so truyen cac tay so;


Rbx=0.432;% Wheel Radius(m);

G=82500;% of vehicle weight (N);

f=0.02;% He so bam;

C=0.85;

A=1.7*2.53;% Dien tich chinh dien;

g=10;% Field Acceleration


Ne=81*(0.5*(n/3200)+1.5*(n/3200).^2-1*(n/3200).^3) ;% Cong suat tinh toan;

V1=0.377*n*Rbx/i1;% Van toc tai so 1;

V2=0.377*n*Rbx/i2;% Van toc tai so 2

V3=0.377*n*Rbx/i3;% Van toc tai so 3;

V4=0.377*n*Rbx/i4;% Van toc tai so 4;

V5=0.377*n*Rbx/i5;% Van toc tai so 5;


% TRACTION VISION
Me=Ne*10.^4./(1.047*n);% Momen tinh toan; Fk1=Me*i1*0.85/Rbx;
% Luc keo tai tay so 1; Fk2=Me*i2*0.85/Rbx;% Luc keo tai tay so 2;
Fk3=Me*i3*0.85/Rbx;% Luc keo tai tay so 3; Fk4=Me*i4*0.85/Rbx;
% Luc keo tai tay so 4; Fk5=Me*i5*0.85/Rbx;% Luc keo tai tay so 5;
Fw1=1.24*C*A*V1.^2/25.92;%Luc can khong khi tai van toc v1;
Fw2=1.24*C*A*V2.^2/25.92;%Luc can khong khi tai van toc v2;
Fw3=1.24*C*A*V3.^2/25.92;%Luc can khong khi tai van toc v3;
Fw4=1.24*C*A*V4.^2/25.92;%Luc can khong khi tai van toc v4;
Fw5=1.24*C*A*V5.^2/25.92;%Luc can khong khi tai van toc v5;
Ff=G*f;% Luc can lan;
Ffw=Ff+Fw5;% Total rolling force and air resistance;
plot(V1,Fk1,'red',V2,Fk2,'blue',V3,Fk3,'green',V4,Fk4,'yellow',V5,Fk5,'black');
hold on;
plot(V5,Ffw,'x-');
hold on;
syms x y;
y=0*x+Ff; ezplot(y,
[0,85.2]);
title('DO THI LUC KEO');
xlabel('v (km/h)');
ylabel('F (N)')
legend('Fk1','Fk2','Fk3','Fk4','Fk5','Ff+Fw','Ff');

Result:

Heed:
 Syms commands are commands for declaring symbolic variables, generating
symbolic expressions, and performing symbolic calculations.
 ezplot is also a function used to draw graphs
 ezplot and plot are two functions in matlab that are used to draw charts. plot is
used to draw simple 2D charts, while ezplot is used to plot curves and more
complex functions.
4.2. Application of matlab in Automotive
Computational Design Calculate the hardness of tweezers with
the initial parameters as follows:
Index of Leaves Width b, cm Tweezers leaf
thickness h, cm
1-6 4,5 0,70
7-9 4,5 0,575
1/2 Length of the tweezers (from the hanging light to the tip of the leaf):
l(1)=68.5; l(2)=67.2; l(3)=57.6; l(4)=50.4; l(5)=43.0; l(6)=35.0; l(7)=28.0; l(8)=20.6;
l(9)=1 3.0

Applicable formula:

In which: is the experimental coefficient:


         
Ak+1=L1- LK+1, where LK is 1/2 of the length of the kth tweezer leaf (calculated
from the hanging light to the tip of the leaf)

Công thức tính Y: Yk = ∑ Jk


i=1
Matlab commands used to calculate the stiffness of tweezers
%% Data Entry
h(1)=0.7; h(2)=0.7; h(3)=0.7; h(4)=0.7; h(5)=0.7; h(6)=0.7; h(7)=0.575; h(8)=0.575;
h(9)=0.575; b=4.5; al=0.85; E=2100000; l(1)=68.5; l(2)=67.2; l(3)=57.6; l(4)=50.4;
l(5)=43.0; l(6)=35.0; l(7)=28.0; l(8)=20.6; l(9)=13.0; l(10)=0;
%% Calculate the geometric properties of tweezers
Jk=b*h.^3/12; %%Essence Moment Essence
Jk=cumsum(Jk); %%If A is a vector, B = cumsum(A) will give the result that vector
B has elements that are the cumulative sum of the elements of vector A.
Yk=1./Jk; Yk(10)=0;
=-diff(Yk); %%Calculate the deviation between adjacent elements of the X vector
a=l(1)*ones(1,10)-l; %% ak+1 = l1 – lk+1 (k =
19). a=a(2:10);
%% Calculate the stiffness of the tweezers
C=al*6*E/sum(a.^3.*DYk)
After running the result C = 28.2741

You might also like