disp('Welcome to the
Projectile Flight program');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Obtain inputs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
muzzleVelocity =
input('Please enter the muzzle velocity in metres/second...');
barrelAngle =
input('Please enter the angle of the barrel in degrees...');
shots = input('How
many entries would you like in the flight table? ');
shots =
round(shots); %
Incase they entered a non integer
barrelAngle =
barrelAngle*pi/180.0;
%
Convert to radians
Projectile Code (Cont)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
flightTime =
2*muzzleVelocity*sin(barrelAngle)/gravity;
%
Time before shell impacts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Construct a vector
of times, being shots+1 in
% length with values
linearly spaced between 0
% and the flight
time of the shell
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
times =
linspace(0,flightTime,shots+1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate all the
x & y co-ordinates. Note
% that these are
vector/matrix operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
horizontal =
muzzleVelocity*cos(barrelAngle)*times;
vertical =
muzzleVelocity*sin(barrelAngle)*times - ...
|
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com 0.5*gravity*times.*times;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Output results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('\n The
total shell flight time is %5.2f seconds\n',flightTime);
fprintf('\n Time\t
Horizontal\t Vertical\n');
combined = [times ;
horizontal ; vertical];
fprintf('%5.2f\t%6.1f\t\t%6.1f\n',combined);
plot(horizontal,vertical,'+-');
xlabel('Horizontal
Distance');
ylabel('Vertical
Distance');
title(strcat('Projectile
Motion with muzzle velocity',...
|
num2str(muzzleVelocity),' m/s
and angle ', ...
|
num2str(barrelAngle/pi*180)));
17.16 Projectile Run
>> projectile
Welcome to the
Projectile Flight program
Please enter the
muzzle velocity in metres/second...70
Please enter the
angle of the barrel in degrees...35
How many entries
would you like in the flight table? 20
The total shell flight time is 8.19 seconds
Time
Horizontal Vertical
0.00 0.0 0.0
0.41 23.5 15.6
0.82 46.9 29.6
1.23 70.4 41.9
1.64 93.9 52.6
2.05
117.3 61.6
2.46
140.8 69.0
2.86
164.3 74.8
3.27
187.7 78.9
3.68
211.2 81.3
4.09
234.7 82.2
4.50
258.2 81.3
4.91
281.6 78.9
5.32
305.1 74.8
5.73
328.6 69.0
6.14
352.0 61.6
6.55
375.5 52.6
6.96
399.0 41.9
7.37
422.4 29.6
7.78
445.9 15.6
8.19
469.4 0.0
17.17 Projectile Plot
17.18 Review
• Importance of I/O
in a program
• disp
• format
• input
- input of strings
• file concept
• fprintf
• fscanf
18 ARRAYS IN MATLAB 1 – VECTORS
• Often desirable to
collect a sequence of values together as a single object
- e.g., temperature
readings for a day
- array is the
general data structure for this supported by most languages
• Matlab is
constructed around the concept of an array/Matrix
- MATrix LABoratory
- virtually all
built-in operations work on arrays transparently
• Today’s lecture
- introduces vectors
(1 dimensional arrays)
• construction
• addressing
• usage
References: For Engineers (Ch. 1, 2)
Mastering
(Ch. 6)
User’s
Guide (Ch. 6)
18.1 Motivation
• Often it is
desirable to collect a number of data values together “in one place”
For instance:
Table of under-water
depths and pressures
Class results for an
exam
Heating results for
an aero-foil at different speeds
• Advantages:
- a single “handle” on the data
- individual elements (datum) may
still be accessed
- operations on entire data can
often be carried out simply
- size of data may vary each time
and indeed (depending on programming language) may be varied dynamically
(grown & shrunk)
18.2 Visualising a 1D Array (Vector)
• One common view of
arrays is:
- a series of numbered boxes
- each box may hold a single data
value
- each particular box is addressed
by using its number
- the collection of boxes together
has the name of the array
• For example a
table of temperatures:
- the array (vector) is called
celcius
- it has 5 elements (numbered 1 to
5)
- element number 2 contains the
value 20
18.3 Matlab & Arrays
• Matlab was
designed to strongly support arrays
- most operations treat scalars
and arrays in exactly the same way
e.g.,
X = Y + Z
X may be a scalar,
vector or multi-dimensional array depending on what Y and Z are.
|
• in most
programming languages different code would be required for each of the above
cases
- arrays can be dynamically
created and altered in size
e.g.,
arr1 = 1:10;
arr1(11) = 11;
• in most
programming languages the size of an array is fixed at compile time and may
not be altered in the program
• This in-built
support for arrays in Matlab means:
- it is often relatively easy and
straight-forward to solve problems (many problems in engineering &
science are naturally expressed with matrices)
- it is easy for novice
programmers (even experienced) to make errors
18.4 Vector Creation
• Matlab provides a
number of mechanisms for the explicit creation of arrays:
square brackets [] When the individual elements are
listed
colon operator : When a starting value, final
value and step-size are known (sequence)
linspace &
logspace To create linear and
exponential sequences of a set size
• For example:
>> theta=[0
pi/4 pi/2 3*pi/4 pi]
theta =
0 0.7854
1.5708 2.3562 3.1416
>> theta =
[theta pi+theta(2:end)]
theta =
Columns 1 through 7
0
0.7854 1.5708 2.3562
3.1416 3.9270 4.7124
Columns 8 through 9
5.4978
6.2832
>>
sinValues=sin(theta)
sinValues =
Columns 1 through 7
0
0.7071 1.0000 0.7071
0.0000 -0.7071 -1.0000
Columns 8 through 9
18.5 Vector Creation Example
-0.7071
-0.0000
>> gamma =
0:0.25:2
gamma =
Columns 1 through 7
0
0.2500 0.5000 0.7500
1.0000 1.2500 1.5000
Columns 8 through 9
1.7500
2.0000
>> gamma =
gamma*pi
gamma =
Columns 1 through 7
0
0.7854 1.5708 2.3562
3.1416 3.9270 4.7124
Columns 8 through 9
5.4978
6.2832
>> cosValues =
cos(gamma)
cosValues =
Columns 1 through 7
1.0000
0.7071 0.0000 -0.7071
-1.0000 -0.7071 -0.0000
Columns 8 through 9
0.7071
1.0000
Vector Creation
(Cont)
>> cosPlusSin
= cosValues + sinValues
cosPlusSin =
Columns 1 through 7
1.0000
1.4142 1.0000 0.0000
-1.0000 -1.4142 -1.0000
Columns 8 through 9
-0.0000
1.0000
>> sigma =
linspace(0,2*pi,9)
sigma =
Columns 1 through 7
0
0.7854 1.5708 2.3562
3.1416 3.9270 4.7124
Columns 8 through 9
5.4978
6.2832
>> tanValues =
tan(sigma)
tanValues =
1.0e+16 *
Columns 1 through 7
0
0.0000 1.6331 -0.0000
-0.0000 0.0000 0.5444
Columns 8 through 9
-0.0000
-0.0000
18.6 Addressing the Elements of a Vector
• Elements of a
vector are accessing by specifying their number
- indexing uses integer values,
and starts with 1 for the first element
• Circle brackets ()
used to enclose indexes
• Indexes can be
scalars, or arrays themselves!
• For example:
>> tanValues(1),
tanValues(2)
ans =
0
ans =
1.0000
>>
cosValues(1:2:9)
ans =
1.0000 0.0000
-1.0000 -0.0000 1.0000
>>
sinValues([2 6 5])
ans =
0.7071 -0.7071
0.0000
>>
sinValues(9:-1:1)
ans =
Columns 1 through 7
-0.0000
-0.7071 -1.0000 -0.7071
0.0000 0.7071 1.0000
Columns 8 through 9
0.7071 0
18.7 Column vs. Row Vectors
• By default vectors
in Matlab are row vectors
- a single row with
multiple columns
• Matlab also
supports column vectors
• Means of creation
are:
- square bracket [] constructor
with semi-colons or single elements per line
- transposing a row vector
Note: An array with
multiple columns & vectors is a matrix (2D array). That is next lecture’s
topic.
|
18.8 Column vs Row Example
>> a = [1 2 3
4 5]
a =
1 2
3 4 5
>> b=a'
b =
1
2
3
4
5
>> a*b
ans =
55
>> c=[6; 7; 8;
9; 10]
c =
6
7
8
9
10
>> d=[11
12
13
14
15]
d =
11
12
13
14
15
18.9 Scalar-Array Mathematics
• Scalars & arrays
may be combined in a single expression using the normal operators +*-/
- extremely useful
& intuitive
• Basic rule
apply the scalar
operation to each element of the array
• For example:
>>
quarters=0:0.25:2
quarters =
Columns 1 through 7
0 0.2500
0.5000 0.7500 1.0000
1.2500 1.5000
Columns 8 through 9
1.7500
2.0000
>>
circle=quarters*pi
circle =
Columns 1 through 7
0
0.7854 1.5708 2.3562
3.1416 3.9270 4.7124
Columns 8 through 9
5.4978
6.2832
>>
strictlyPositive = quarters*4 + 1
strictlyPositive =
1
2 3 4
5 6 7
8 9
18.10 Example cel2far.m
A program to produce
a table of conversions from temperature in celcius to fahrenheit.
|
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cel2far.m
% Program to produce a table of
conversion
% from temperature in celcius to
fahrenheit
% using the formula
% F = C*1.8 + 32
% User enters lower and upper bounds,
as
% well as the step interval for
temperatures
% in celcius. Program produces a
table of
% celcius versus fahrenheit entries.
|
% Author: Spike
% Date: 17/2/1999
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
% Get inputs
%%%%%%%%%%%%%%%%%%%%%%%%
disp('Celcius to
Fahrenheit conversion');
lower =
input('Please enter the min. temp. in celcius...');
upper =
input('Please enter the max. temp. in celcius...');
step = input('Please
enter the step size in degrees for the table...');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
celcius =
lower:step:upper;
fahrenheit =
1.8*celcius + 32;
combined = [celcius;
fahrenheit];
fprintf('%8s\t%s\n','Celcius','Fahrenheit');
disp('
--');
fprintf('%5.1f\t\t%5.1f\n',combined);
18.11 cel2far Run
>> cel2far
Celcius to
Fahrenheit conversion
Please enter the
min. temp. in celcius...-10
Please enter the
max. temp. in celcius...40
Please enter the
step size in degrees for the table...5
Celcius Fahrenheit
10.0 14.0
-5.0
23.0
0.0
32.0
5.0
41.0
10.0
50.0
15.0
59.0
20.0
68.0
25.0
77.0
30.0
86.0
35.0
95.0
40.0 104.0
>> diary off
18.12 Array-Array Mathematics
• Matlab also
supports mathematical operations between arrays
- arrays must be of
same size & dimensionality
- standard operators
interpreted as per mathematical definitions (matrix operations – see next
lecture)
- additional “dot”
operators provided to mimic scalar operations
• For example:
>>
strictlyPositive
strictlyPositive =
1 2
3 4 5
6 7 8
9
>> squares =
strictlyPositive.^2
squares =
1 4
9 16 25
36 49 64
81
>>
strictlyPositive = quarters+quarters+quarters+quarters+1
strictlyPositive =
1 2
3 4 5
6 7 8
9
>> cubes =
squares .* strictlyPositive
cubes =
1 8
27 64 125
216 343 512
729
>> oneOnX =
squares ./ cubes
oneOnX =
Columns 1 through 7
1.0000 0.5000
0.3333 0.2500 0.2000
0.1667 0.1429
Columns 8 through 9
0.1250
0.1111
18.13 Example – bouncing.m
A program to
calculate the height of an object as it bounces.
|
User supplies the
initial height from which the object is dropped, the number of bounces to
simulate, and the elasticity of the object.
|
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com
The elasticity
determines how high the object returns after a bounce via the following
formula:
>> bouncing
Please input the
initial height...100
Please input the
object's elasticity [0-1]...0.7
Please input the
number of bounces required...5
Bounce Table
bounce: 0
1 2 3
4 5
height: 100.0 49.0
24.0 11.8 5.8
2.8
18.14 bouncing.m Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% bouncing.m
% A script to simulate the bouncing
of a ball or
% other similar object. The user
enters three
% values: the
initial height from which the
% object is dropped,
the elasticity of the
% object (a value
between 0 and 1, 1 meaning
%
"perfect" elasticity) and the number of
% bounces to be simulated.
|
% The program employs the following
equation to
% determine the height of a new
bounce:
% Hnew = Hold*Elasticity^2
% i.e., New height is the old height
times the
% square of the
object's elasticity.
|
% Rewriting the equation so we may
use vectors
% we see
% Hn = H0*Elasticity^(2*n)
% i.e., height on bounce n is the
height of
% initial drop times
the elasticity raised to
% the 2n.
|
% Author: Spike
% Date: 17/2/1999
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Obtain inputs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
initialHeight =
input('Please input the initial height...');
elasticity =
input('Please input the object''s elasticity [0-1]...');
bounces =
input('Please input the number of bounces required...');
bouncing.m (Cont)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create the two
"building block" vectors that
% are needed.
bounceVector is simply a vector
% counting the
number of bounces. It is used in
% output and the
calculations. elasticRep is
% simply a vector of
size (bounces+1) with
% each element set
to the elasticity of the
% object. It is used
to obtain a vector of
% elasticities ^2n
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bounceVector =
0:bounces;
elasticRep =
linspace(elasticity,elasticity,bounces+1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Heart of the
program. The vector heights is
% built using the
rewritten equation.
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
heights =
initialHeight*elasticRep.^(2*bounceVector);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Output the results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('\nBounce
Table\n');
fprintf('%8s:','bounce');
fprintf('%5.0f ',bounceVector);
disp(' ');
fprintf('%8s:','height');
fprintf('%5.1f ',heights);
disp(' ');
18.15 Review
• vectors as models
of the real-world
• arrays in Matlab
• Creating vectors
- square brackets
- colon operator
- linspace &
logspace
• Addressing vector
elements
• Row vs. column
vectors
• scalar-array
mathematics
• array-array
mathematics
19 MATLAB ARRAYS 2 – MATRICES
• As already seen
arrays are a useful data type
• Arrays need not be
limited to 1-dimension:
- many real-world
problems have higher dimensionality
• Today’s lecture:
- continues with
arrays in Matlab
- concentrates on 2D
(matrices) and higher dimensioned arrays
References: For Engineers (Ch. 1, 3, 6)
User’s
Guide (Ch. 6, 7)
Mastering
(Ch. 6, 7, 16)
19.1 2D(+) Arrays – Motivation
• Much real-world
data has a higher dimensionality than one.
|
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com • For example:
- Image on the monitor. Can be
viewed as a 2D grid of pixels, where for each pixel an R-G-B intensity is
kept.
|
- Terrain map. Can be viewed as a
2D grid of map heights.
|
- Class results. Can be viewed as
a 2D grid with each row being a different student and each column being a
different assignment or exam.
|
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com - Stock market figures. Can be viewed as a 2D grid with time as one axis and the individual stocks as the 2nd axis. |
KURSUS MATLAB ONLINE Skripsi, Tesis, DISERTASI 081219449060
Selasa, 13 Januari 2015
KURSUS MATLAB ONLINE Skripsi, Tesis, DISERTASI 081219449060
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar