SlideShare a Scribd company logo
1 of 60
Programming
BY
R.IMMANUAL
Certified on MATLAB
Onramp by Math works
Training services(MATLAB
Academy)
About this Session
• We will coverthe following
topics
• MATLAB basics
• Arrays: Unlocking potential of
MATLAB
Starting and Exiting MATLAB
• We will go over starting a MATLABsession, layoutof MATLAB
window, MATLAB editor,etc.
• Also see video“GettingStarted with MATLAB”on MATLAB site
http://in.mathworks.com/videos/getting-started-with-matlab-68985.html
Open and Explain it…
Customizing our window
 Manual
 Using layout
 How create a new editor
 How to set path
MATLAB Code: Main Code
Blocks %% Define Parameters and Initial Conditions
param.g =
9.81;
% gravitational
acceleration
% air drag coefficient
param.kappa =
0.006; u0 =
35*cos(pi/4); v0
= 35*sin(pi/4);
%% Setting up and Solving the problem
X0 = [0; 0;
u0; v0];
tSpan = [0
20];
% starting position is the
origin
% starting velocity is given
% simulation time
[tOut, XOut] = ode45(@ballTrajectoryFun,tSpan,X0, [],
param);
%% Displaying the
results figure(1);
plot(XOut(:,1),XOut(:,2
),'bo');
xlabel('x (m)'); ylabel('y (m)');
%% Animating results
exitCode = ballAnimation(tOut,XOut);
Input
block
Computation
Output
block
MATLAB Code: Key Parts
%% Define Parameters and Initial
Conditions
param.g = 9.81;
u0 = 35*cos(pi/
Comment
Assignment
(Math)Expression
[tOut, XOut] = ode45(@bal
Calling a function
plot(XOu
Calling a function
MATLAB Code
%% Define Parameters and Initial
Conditions
param.g = 9.81;
% gravitational
acceleration
% air drag coefficient
param.kappa = 0.006;
u0 = 35*cos(pi/4);
v0 = 35*sin(pi/4);
%% Setting up and Solving the
problem
X0 = [0; 0;u0; v0];
tSpan = [0 20];
% starting position is the
origin
% starting velocity is given
% simulation time
[tOut, XOut] = ode45(@ballTrajectoryFun,tSpan,X0, [], param);
%% Displaying the results
figure(1);
plot(XOut(:,1),XOut(:,2),'bo');
xlabel('x (m)'); ylabel('y (m)');
%% Animating results
exitCode = ballAnimation(tOut,XOut);
Basic Data Types
• Matlab easily works with
arrays
• Scalars, vectors and arrays
• Assigningvariables
• Row vs. column vectors
• Arrays /Matrices
• Suppress“echo”
• Variables arecase-sensitive
Basic MathematicalExpressions
Variable Meaning
pi Number /
eps Machine precision
i Imaginary unit
inf Infinity
NaN Not a Number (e.g., 0/0)
ans Last displayedresult
end Last element of array
realmax Largest real number
intmax Largest integer
Scalar Operations Special
Variables
• + - * / ^
• log, exp
• pow, sqrt
• sin, cos, tan
• asin, acos, atan
• rem, round, ceil, floor
When type functions we use ()… pow2(5)
Tasks from Entering Commands
Task 01
 Try multiplying the numbers 3 and 5 together
with the command 3*5.
Task 02
 Try assigning the 3*5 calculation to a variable
named m as shown: m = 3*5.
Task 03
 Try entering the command m = m + 1 to see
what happens.
Task 04
 Now try creating a variable named y that has
the value m/2.
Task 05
 Try entering k = 8-2; with a semicolon at the
end.
 Echo will be supressed
Task 06
 Try entering k = 8-2; with a semicolon at the
end.
 Echo will be supressed
Task 07
 Try pressing the Up arrow to return to the
command m =3*5 and edit the command to
be m = 3*k.
 Echo will be supressed
Tasks on variables
Task 1
 Try clearing all variables by entering the
command clear.
Tasks 02
 clean up the command window using the clc
command..
Task 03
 Try creating a variable called x with a value
of π/2.
Task 04
 Try using the sin function to calculate the sine
of x. Assign the result to a variable named y.
Task 06
 Now try using the sqrt function to calculate the
square root of -9. Assign the result to a
variable named z..
 CREATE pi = 9;
 Clear the pi variable
Arrays are the most powerful aspect of
MATLAB
•We will learn
•Building arrays
•Colon notations
•Array operations and functions
•Also view “Working with Arrays in
MATLAB” on MATLAB website:
http://in.mathworks.com/videos/working-with-arrays-in-matlab-
69022.html
Building Arrays
 Create random matrix (a = rand(6,4))
 Indexing of an array (a(1,2))
 Assign a value to the array elements
(a(1,2)=2;)
 Assign an empty matrix a=[];
 Create an Identity matrix of c =eye(3);
 Combine two matrix C = horzcat(A1,...,AN)
(same rows)
Building Arrays
 Manually crate arrays a= [1 2 3 ; 1 2 3]
 Transpose of a matrix a’
 Elemental operation a(2,1) select that element
 Size of a matrix size (a)
 Ones(m,n)
 diag(a)
Colon notations
 A=1:5;
 A(1:3,5)
Task 01
 Create a variable named x with a value of 4.
Task 02
 Create an array named x with two elements in
a single row:
7 and 9.
Task 03
 Now create an array named x with two
elements, 7 and 9, in a single column. Try
recalling the previous command and changing
the space between the numbers to a
semicolon (;).
Task 04
 Now try creating a 1-by-3 row vector
named x that contains the values 3, 10,
and 5 in that order.
Task 05
 Now try creating a 3-by-1 column vector
named x that contains the values 8, 2, and -
4 in that order..
Task 06
 Try creating a matrix named x with the values
shown below.
5 6 7
8 9 10
Task 07
 Try creating a 1-by-2 row vector named x that
contains sqrt(10) as its first element
and pi^2 (π2) as its second element.
Task 08
 Try creating a row vector named x that
contains the values 1, 2, and 3, in that order.
Task 09
 Try recreating the row vector named x (still
with values 1, 2, and 3), but this time using
the : operator.
Task 10
 Try creating a row vector named x that starts
at 1, ends at 5, and each element is
separated by 0.5.
Task 11
 Try creating a row vector named x that starts
at 3 and ends at 13, with each element
separated by 2.
Task 12
 Try creating a row vector named x that starts
at 3 and ends at 13, with each element
separated by 2.
Task 13
 Try creating a row vector named x that starts
at 1, ends at 10, and contains 5 elements.
x = linspace(0,1,5)
start
End
Number of Components
Task 14
 Transpose x from a row vector to a column
vector using the transpose operator.
Task 15
 In a single command, create a column vector
named x that starts at 5, ends at 9 and has
elements that are spaced by 2.
Task 16
 Try creating a variable named x that is a 5-by-
5 matrix of random numbers.
rand
Task 17
 Try using rand to create an array that
contains 5 rows and 1 column. Assign the
result to a variable named x.
rand
Task 18
 Now try using the zeros function to create a
matrix of all zeros that has 6 rows
and 3 columns (6-by-3). Assign the result to a
variable named x.
rand
Indexing into Arrays
 Task 20
 Create data variable contains 7,4 random
values
 Try creating a variable v that contains the
value in the 6throw and 3rd column of the
variable data.
Task 21
 Info: You can use the MATLAB
keyword end as either a row or column index
to reference the last element.
>> x = A(end,2);
 Now try using the end keyword to obtain the
value in the last row and 3rd column of the
variable data. Assign this value to a variable
named v.
rand
Basic Mathematical Expressions
“Scalar” Operations Matrix Operations
• + – * / ^
•log, exp • logm, expm
•power, sqrt • mpower, sqrtm
•sin, cos, tan • sum,prod,cumsum,cumprod
•asin, acos, atan • min, max, mean, std
•rem, round, ceil, floor • length, size, eig
Task 01
 Try creating a vector vs that is the sum of the
vectors v1and v2.
rand
Task 02
 Try creating a variable va that contains the
value vs divided by 2
 Matrix multiplication
 Elemental multiplication
rand
Task 03
 Info: Basic statistical functions in MATLAB
can be applied to a vector to produce a single
output. The maximum value of a vector can
be determined using the max function.
>> xMax = max(x)
 Try creating a variable vm containing the
maximum of the va vector.
rand
Task 04
 Using the round function, create a variable
named vrwhich contains the rounded average
volumes, va.
rand
Task 04
 The .* operator performs elementwise
multiplication and allows you to multiply the
corresponding elements of two equally sized
arrays.
 z = [3 4] .* [10 20]
 z = 30 80
rand
Task 05
 Try creating a variable
named dsize containing the size of a matrix.
rand
Application Oriented Task
 Solution to system of linear equation
Solutions to Systems of Linear Equations
 Example: a system of 3 linear equations with 3 unknowns (x1, x2, x3):
3x1 + 2x2 – x3 = 10
-x1 + 3x2 + 2x3 = 5
x1 – x2 – x3 = -1
Then, the system can be described as:
Ax = b














1
1
1
2
3
1
1
2
3
A











3
2
1
x
x
x
x












1
5
10
b
Let :
Task 01
Solutions to Systems of Linear
Equations (con’t…)
 Solution by Matrix Inverse:
Ax = b
A-1Ax = A-1b
x = A-1b
 MATLAB:
>> A = [ 3 2 -1; -1 3 2; 1 -1 -1];
>> b = [ 10; 5; -1];
>> x = inv(A)*b
x =
2.0000
1.0000
2.0000
Answer:
x1 = 2, x2 = 1, x3 = 2
• Solution by Matrix Division:
The solution to the equation
Ax = b
can be computed using left division.
Answer:
x1 = 2, x2 = 1, x3 = 2
 MATLAB:
>> A = [ 3 2 -1; -1 3 2; 1 -1 -1];
>> b = [ 10; 5; -1];
>> x = Ab
x =
2.0000
1.0000
2.0000
Task 02
•Consider the following example (Marks earned by students)
Name Math Programmin
g
Thermodyna
mics
Mechanics
Amit 24 44 36 36
Bhavna 52 57 68 76
Chetan 66 53 69 73
Deepak 85 40 86 72
Elizabeth 15 47 25 28
Farah 79 72 82 91
HOW to Do This……
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx

More Related Content

Similar to COMPANION TO MATRICES SESSION II.pptx

Similar to COMPANION TO MATRICES SESSION II.pptx (20)

Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
bobok
bobokbobok
bobok
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
2. Chap 1.pptx
2. Chap 1.pptx2. Chap 1.pptx
2. Chap 1.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Lecture two
Lecture twoLecture two
Lecture two
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
Matlab
MatlabMatlab
Matlab
 

More from imman gwu

DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONDSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONimman gwu
 
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYINTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYimman gwu
 
UAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESUAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESimman gwu
 
GWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDGWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDimman gwu
 
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTDRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTimman gwu
 
COMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptxCOMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptximman gwu
 
COMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptxCOMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptximman gwu
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptximman gwu
 
imman resume final
imman resume finalimman resume final
imman resume finalimman gwu
 

More from imman gwu (9)

DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONDSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
 
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYINTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
 
UAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESUAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USES
 
GWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDGWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATED
 
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTDRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
 
COMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptxCOMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptx
 
COMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptxCOMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptx
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptx
 
imman resume final
imman resume finalimman resume final
imman resume final
 

Recently uploaded

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

COMPANION TO MATRICES SESSION II.pptx

  • 1. Programming BY R.IMMANUAL Certified on MATLAB Onramp by Math works Training services(MATLAB Academy)
  • 2. About this Session • We will coverthe following topics • MATLAB basics • Arrays: Unlocking potential of MATLAB
  • 3. Starting and Exiting MATLAB • We will go over starting a MATLABsession, layoutof MATLAB window, MATLAB editor,etc. • Also see video“GettingStarted with MATLAB”on MATLAB site http://in.mathworks.com/videos/getting-started-with-matlab-68985.html Open and Explain it…
  • 4. Customizing our window  Manual  Using layout  How create a new editor  How to set path
  • 5. MATLAB Code: Main Code Blocks %% Define Parameters and Initial Conditions param.g = 9.81; % gravitational acceleration % air drag coefficient param.kappa = 0.006; u0 = 35*cos(pi/4); v0 = 35*sin(pi/4); %% Setting up and Solving the problem X0 = [0; 0; u0; v0]; tSpan = [0 20]; % starting position is the origin % starting velocity is given % simulation time [tOut, XOut] = ode45(@ballTrajectoryFun,tSpan,X0, [], param); %% Displaying the results figure(1); plot(XOut(:,1),XOut(:,2 ),'bo'); xlabel('x (m)'); ylabel('y (m)'); %% Animating results exitCode = ballAnimation(tOut,XOut); Input block Computation Output block
  • 6. MATLAB Code: Key Parts %% Define Parameters and Initial Conditions param.g = 9.81; u0 = 35*cos(pi/ Comment Assignment (Math)Expression [tOut, XOut] = ode45(@bal Calling a function plot(XOu Calling a function
  • 7. MATLAB Code %% Define Parameters and Initial Conditions param.g = 9.81; % gravitational acceleration % air drag coefficient param.kappa = 0.006; u0 = 35*cos(pi/4); v0 = 35*sin(pi/4); %% Setting up and Solving the problem X0 = [0; 0;u0; v0]; tSpan = [0 20]; % starting position is the origin % starting velocity is given % simulation time [tOut, XOut] = ode45(@ballTrajectoryFun,tSpan,X0, [], param); %% Displaying the results figure(1); plot(XOut(:,1),XOut(:,2),'bo'); xlabel('x (m)'); ylabel('y (m)'); %% Animating results exitCode = ballAnimation(tOut,XOut);
  • 8. Basic Data Types • Matlab easily works with arrays • Scalars, vectors and arrays • Assigningvariables • Row vs. column vectors • Arrays /Matrices • Suppress“echo” • Variables arecase-sensitive
  • 9. Basic MathematicalExpressions Variable Meaning pi Number / eps Machine precision i Imaginary unit inf Infinity NaN Not a Number (e.g., 0/0) ans Last displayedresult end Last element of array realmax Largest real number intmax Largest integer Scalar Operations Special Variables • + - * / ^ • log, exp • pow, sqrt • sin, cos, tan • asin, acos, atan • rem, round, ceil, floor When type functions we use ()… pow2(5)
  • 11. Task 01  Try multiplying the numbers 3 and 5 together with the command 3*5.
  • 12. Task 02  Try assigning the 3*5 calculation to a variable named m as shown: m = 3*5.
  • 13. Task 03  Try entering the command m = m + 1 to see what happens.
  • 14. Task 04  Now try creating a variable named y that has the value m/2.
  • 15. Task 05  Try entering k = 8-2; with a semicolon at the end.  Echo will be supressed
  • 16. Task 06  Try entering k = 8-2; with a semicolon at the end.  Echo will be supressed
  • 17. Task 07  Try pressing the Up arrow to return to the command m =3*5 and edit the command to be m = 3*k.  Echo will be supressed
  • 18. Tasks on variables Task 1  Try clearing all variables by entering the command clear.
  • 19. Tasks 02  clean up the command window using the clc command..
  • 20. Task 03  Try creating a variable called x with a value of π/2.
  • 21. Task 04  Try using the sin function to calculate the sine of x. Assign the result to a variable named y.
  • 22. Task 06  Now try using the sqrt function to calculate the square root of -9. Assign the result to a variable named z..  CREATE pi = 9;  Clear the pi variable
  • 23. Arrays are the most powerful aspect of MATLAB •We will learn •Building arrays •Colon notations •Array operations and functions •Also view “Working with Arrays in MATLAB” on MATLAB website: http://in.mathworks.com/videos/working-with-arrays-in-matlab- 69022.html
  • 24. Building Arrays  Create random matrix (a = rand(6,4))  Indexing of an array (a(1,2))  Assign a value to the array elements (a(1,2)=2;)  Assign an empty matrix a=[];  Create an Identity matrix of c =eye(3);  Combine two matrix C = horzcat(A1,...,AN) (same rows)
  • 25. Building Arrays  Manually crate arrays a= [1 2 3 ; 1 2 3]  Transpose of a matrix a’  Elemental operation a(2,1) select that element  Size of a matrix size (a)  Ones(m,n)  diag(a)
  • 27. Task 01  Create a variable named x with a value of 4.
  • 28. Task 02  Create an array named x with two elements in a single row: 7 and 9.
  • 29. Task 03  Now create an array named x with two elements, 7 and 9, in a single column. Try recalling the previous command and changing the space between the numbers to a semicolon (;).
  • 30. Task 04  Now try creating a 1-by-3 row vector named x that contains the values 3, 10, and 5 in that order.
  • 31. Task 05  Now try creating a 3-by-1 column vector named x that contains the values 8, 2, and - 4 in that order..
  • 32. Task 06  Try creating a matrix named x with the values shown below. 5 6 7 8 9 10
  • 33. Task 07  Try creating a 1-by-2 row vector named x that contains sqrt(10) as its first element and pi^2 (π2) as its second element.
  • 34. Task 08  Try creating a row vector named x that contains the values 1, 2, and 3, in that order.
  • 35. Task 09  Try recreating the row vector named x (still with values 1, 2, and 3), but this time using the : operator.
  • 36. Task 10  Try creating a row vector named x that starts at 1, ends at 5, and each element is separated by 0.5.
  • 37. Task 11  Try creating a row vector named x that starts at 3 and ends at 13, with each element separated by 2.
  • 38. Task 12  Try creating a row vector named x that starts at 3 and ends at 13, with each element separated by 2.
  • 39. Task 13  Try creating a row vector named x that starts at 1, ends at 10, and contains 5 elements. x = linspace(0,1,5) start End Number of Components
  • 40. Task 14  Transpose x from a row vector to a column vector using the transpose operator.
  • 41. Task 15  In a single command, create a column vector named x that starts at 5, ends at 9 and has elements that are spaced by 2.
  • 42. Task 16  Try creating a variable named x that is a 5-by- 5 matrix of random numbers. rand
  • 43. Task 17  Try using rand to create an array that contains 5 rows and 1 column. Assign the result to a variable named x. rand
  • 44. Task 18  Now try using the zeros function to create a matrix of all zeros that has 6 rows and 3 columns (6-by-3). Assign the result to a variable named x. rand
  • 45. Indexing into Arrays  Task 20  Create data variable contains 7,4 random values  Try creating a variable v that contains the value in the 6throw and 3rd column of the variable data.
  • 46. Task 21  Info: You can use the MATLAB keyword end as either a row or column index to reference the last element. >> x = A(end,2);  Now try using the end keyword to obtain the value in the last row and 3rd column of the variable data. Assign this value to a variable named v. rand
  • 47. Basic Mathematical Expressions “Scalar” Operations Matrix Operations • + – * / ^ •log, exp • logm, expm •power, sqrt • mpower, sqrtm •sin, cos, tan • sum,prod,cumsum,cumprod •asin, acos, atan • min, max, mean, std •rem, round, ceil, floor • length, size, eig
  • 48. Task 01  Try creating a vector vs that is the sum of the vectors v1and v2. rand
  • 49. Task 02  Try creating a variable va that contains the value vs divided by 2  Matrix multiplication  Elemental multiplication rand
  • 50. Task 03  Info: Basic statistical functions in MATLAB can be applied to a vector to produce a single output. The maximum value of a vector can be determined using the max function. >> xMax = max(x)  Try creating a variable vm containing the maximum of the va vector. rand
  • 51. Task 04  Using the round function, create a variable named vrwhich contains the rounded average volumes, va. rand
  • 52. Task 04  The .* operator performs elementwise multiplication and allows you to multiply the corresponding elements of two equally sized arrays.  z = [3 4] .* [10 20]  z = 30 80 rand
  • 53. Task 05  Try creating a variable named dsize containing the size of a matrix. rand
  • 54. Application Oriented Task  Solution to system of linear equation
  • 55. Solutions to Systems of Linear Equations  Example: a system of 3 linear equations with 3 unknowns (x1, x2, x3): 3x1 + 2x2 – x3 = 10 -x1 + 3x2 + 2x3 = 5 x1 – x2 – x3 = -1 Then, the system can be described as: Ax = b               1 1 1 2 3 1 1 2 3 A            3 2 1 x x x x             1 5 10 b Let : Task 01
  • 56. Solutions to Systems of Linear Equations (con’t…)  Solution by Matrix Inverse: Ax = b A-1Ax = A-1b x = A-1b  MATLAB: >> A = [ 3 2 -1; -1 3 2; 1 -1 -1]; >> b = [ 10; 5; -1]; >> x = inv(A)*b x = 2.0000 1.0000 2.0000 Answer: x1 = 2, x2 = 1, x3 = 2 • Solution by Matrix Division: The solution to the equation Ax = b can be computed using left division. Answer: x1 = 2, x2 = 1, x3 = 2  MATLAB: >> A = [ 3 2 -1; -1 3 2; 1 -1 -1]; >> b = [ 10; 5; -1]; >> x = Ab x = 2.0000 1.0000 2.0000
  • 57. Task 02 •Consider the following example (Marks earned by students) Name Math Programmin g Thermodyna mics Mechanics Amit 24 44 36 36 Bhavna 52 57 68 76 Chetan 66 53 69 73 Deepak 85 40 86 72 Elizabeth 15 47 25 28 Farah 79 72 82 91
  • 58. HOW to Do This……