The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by lbozcu, 2019-01-05 02:30:10

MATLAB NOTE

MATLAB NOTE

COMPUTATIONAL LAB
(ME-106)

INTRODUCTION
TO

MATLAB

By
K.Kiran Kumar
Assistant professor
Mechanical Engineering Department
B.S.Abdur Rahman University
Email:- [email protected]
Ph.no:- 9047475841

WHAT IS MATLAB?

MATLAB (MATrix LABoratory) is basically a high level language
which has many specialized toolboxes for making things easier for us.
 MATLAB is a program for doing numerical computation. It was
originally designed for solving linear algebra type problems using
matrices. It‟s name is derived from MATrix LABoratory.
 MATLAB has since been expanded and now has built-in functions for
solving problems requiring data analysis, signal processing, optimization,
and several other types of scientific computations. It also contains
functions for 2-D and 3-D graphics and animation.
 Powerful, extensible, highly integrated computation, programming,
visualization, and simulation package.
 Widely used in engineering, mathematics, and science.
 Why?

FEATURES

o MATLAB is an interactive system for doing
numerical computations. MATLAB makes use of
highly respected algorithms and hence you can be
confident about your results.

 Powerful operations can be performed using just
one or two commands. You can also build your
own set of functions. Excellent graphics facilities
are included.

MATLAB TOOLBOXES

Math and Analysis Signal & Image Processing

Optimization Signal Processing

Requirements Management Interface Image Processing

Statistics Communications

Neural Network Frequency Domain Identification

Symbolic/Extended Math Higher-Order Spectral Analysis
Partial Differential Equations System Identification
PLS Toolbox Wavelet
Mapping Filter Design

Spline

Control Design

Data Acquisition and Import Control System

Data Acquisition Fuzzy Logic

Instrument Control Robust Control

Excel Link μ-Analysis and Synthesis
Portable Graph Object Model Predictive Control

SIMULINK

 A simulation tool for dynamic systems

Input Output

System

 Simulink library Browser:

 Collection of sources, system modules, sinks

WHAT ARE WE INTERESTED IN?

 MATLAB is too broad tool used in industry and Research for real
time interfacing of sensors and machine vision etc. and
programming the real time systems for active control of the
system behavior.

 For our course purpose in this Laboratory we will have brief
overview of basics and learn what can be done with MATLAB at
beginner level.

WHY DO WE
NEED TO

PERFORM
ANALYSIS IN
MATLAB ???

AREAS WHERE MECHANICAL
ENGINEERS USE MATLAB

 Solving kinematics, kinetics and complete
dynamic systems control of Automotive
suspension , Thermal systems etc.,

AERO PLANE SUSPENSION OF LANDING GEAR

M

M

Mg Fs Fc

Yo

Ys M d 2 yo  Mg  Fc  Fs
dt 2

Yin

BASICS Displacement
D
distance
35 Metres Time

Speed Velocity
65 m/s V

0-60 m/s Time
in 8.6
second Acceleration
A

Time

UNDAMPED FREE VIBRATION

Displacement d = D sinnt Displacement

D Time 1 Frequency
T
T m
k
Period, Tn in [sec]

Frequency, fn= 1 in [Hz = 1/sec]
Tn

k
n= 2  fn = m

CONTINUED…

Natural frequency of a simple single degree of
freedom undamped system is given by the
equation

ωN = square root of (stiffness / mass)

Usually we do not want structures to vibrate in
resonance

COMPONENTS OF A CAR

For comfortable ride in a car requires analysis of
car frame and many other components, e.g.
exhaust systems (bellows), shock absorber, tire
etc.

Let us look into a shock absorber in more detail

 We know what a typical shock absorber does
saves us from unpleasant vibration.

Let us look at a quarter bus/truck/car model

ms xs
ks cs
xu
mu u
kt

u = road profile input ks = suspension spring constant

kt = tire spring constant cs = suspension damping constant

mu = unsprung mass ms = sprung mass

xu = displacement of unsprung masxss = displacement of sprung mass

FOUR WHEELER SUSPENSION SYSTEM 15

 Consider the following suspension system.
 Solve for y given yin

M

Mg

Suspension system y
ys

yin

SUSPENSION SYSTEM IN FOUR
WHEELER

CONTINUED…

CONTINUED…

CONTINUED…

CONVENTIONAL PASSIVE SUSPENSION

sprung mass zs
(body) Ms
suspension damper
suspension spring zu
unsprung mass zr
(wheel, axle) Mu

tyre stiffness Kt

MATLAB MODEL FOR
BUS SUSPENSION

Designing an automatic suspension system for a bus

MATLAB SCREEN

VARIABLES

 No need for types. i.e.,
int a;
double b;
float c;
 Accuracy and comfort is very high with matlab codes.
>>x=5;
>>x1=2;

ARRAY, MATRIX

LONG ARRAY, MATRIX

GENERATING VECTORS FROM FUNCTIONS

MATRIX INDEX

OPERATORS (ARITHMETIC)

MATRICES OPERATIONS

THE “DOT OPERATOR”

 By default and whenever possible MATLAB
will perform true matrix operations (+ - *). The
operands in every arithmetic expression are
considered to be matrices.

 If, on the other hand, the user wants the scalar
version of an operation a “dot” must be put in
front of the operator, e.g., .*. Matrices can still
be the operands but the mathematical
calculations will be performed element-by-
element.

 A comparison of matrix multiplication and
scalar multiplication is shown on the next slide.

OPERATORS (ELEMENT BY ELEMENT)

DOT OPERATOR EXAMPLE

>> A = [1 5 6; 11 9 8; 2 34 78]

A=

156

11 9 8

2 34 78

>> B = [16 4 23; 8 123 86; 67 259 5]

B=

16 4 23

8 123 86

67 259 5

DOT OPERATOR EXAMPLE (CONT.)

>> C = A * B % “normal” matrix multiply
C=
2173 483
458 3223 1067
784 24392 3360
5530

>> CDOT = A .* B % element-by-element
CDOT =
20 138
16 1107 688
88 8806 390
134

THE USE OF “.” -OPERATION

MATLAB FUNCTIONS

COMMON MATH FUNCTIONS

BUILT-IN FUNCTIONS FOR HANDLING ARRAYS

MATLAB BUILT-IN ARRAY FUNCTIONS

» eye(2) Standard Arrays

ans = Other such arrays:
ones(n), ones(r, c)
10 zeros(n), zeros(r, c)
01 rand(n), rand(r,c)

» eye(2,3)

ans =

100
010

»

RANDOM NUMBERS GENERATION

COMPLEX NUMBERS HANDLING

FUNCTIONS

MATRIXES AND VECTORS

 x = [1,2,3] , vector-row,
 y=[1;2;3], vector-column,
 x=0:0.1:0.8 , vector x=[0,0.1,0.2,0.3....0.8],
 A = [1,3,5;5,6,7;8,9,10], matrix,
 A(1,2), element of matrix, 1. row, 2. column,
 A(:,2), second column of matrix,
 A(1,:), first row of matrix ,
 C=[A;[10,20,30]] matrix with additional row,
 B=A(2:3,1:2), part of matrix,
 x‟, transpose.

42

MATRIXES AND VECTORS

 size(A), matrix size,
 det(A), determinant,
 inv(A), inverse matrix,
 eye(3), unit matrix,
 zeros(3,4), matrix of zeros,
 rand(3,5), matrix of random values,
 sum(A), sum of elements,
 A*x, matrix-vector product (if dimensions are

corresponding),
 A.*B, element multiplication of two matrixes.
 help sqrt, looking for known command,
 help, help topics are shown,

43

INTRODUCTION TO M-FILES PROGRAMMING

Type-1 Type-2
programming Programming

Program:- Program:-
clc; clc;
clear all; clear all;
p=10,000; p=input('enter the value of p:');
t=2; t=input('enter the value of t:');
r=11; r=input('enter the value of r:');
I=(p*t*r)/100; I=(p*t*r)/100
Solution:- Solution:-
I = 2200 Input:
enter the value of p:10000
enter the value of t:2
enter the value of r:11
Output:
I = 2200

GRAPHICS AND DATA DISPLAY

 2-D plotting functions

>> plot(x,y) % linear Cartesian

>> semilogx(x,y) % logarithmic abscissa

• uses base 10 (10n for axis units)

>> semilogy(x,y) % logarithmic ordinate

• uses base 10 (10n for axis units)

>> loglog(x, y) % log scale both dimensions

• uses base 10 (10n for axis units)

>> polar(theta,rho) % angular and radial

CONTINUED..

 2-D display variants

 Cartesian coordinates

>> bar(x,y) % vertical bar graph

>> barh(x,y) % horizontal bar graph

>> stem(x,y) % stem plot

>> area(x,y) % color fill from horizontal axis to line

>> hist(y,N) % histogram with N bins (default N = 10)

 Polar coordinates

>> pie(y)
>> rose(theta,N) % angle histogram, N bins (default 10)

GRAPHICS AND DATA DISPLAY

 3-D Plotting syntax

 Line

>> plotfunction(vector1, vector2, vector3)

Vector lengths must be the same

► Example

>> a = 1:0.1:30;
>> plot3( sin(a), cos(a), log(a) )

 Pie

>> pie3(vector)

One dimensional data, but 3-D pie perspective

GRAPHICS AND DATA DISPLAY

 3-D surface plotting functions

>> contour(x,y,Z) % projection into X-Y plane
>> surf(x,y,Z) % polygon surface rendering
>> mesh(x,y,Z) % wire mesh connecting vertices
>> waterfall(x,y,Z)

• like mesh but without column connection lines
• used for column-oriented data

BASIC TASK: PLOT THE FUNCTION
SIN(X) BETWEEN 0≤X≤4Π

PLOT THE FUNCTION BETWEEN 0≤X≤4Π


Click to View FlipBook Version