SlideShare a Scribd company logo
© EEE Makers Hub, EEE, KUET
© EEE Makers Hub, EEE, KUET
A Case Study Approach
Learning
Created by:
Md. Rayid Hasan Mojumder | EEE 2k15 | KUET
Learning Matlab: A Case Study approach
2
© EEE Makers Hub, EEE, KUET
Outline
❑ Matlab? Why I will even bother to learn it?
❑ Target audience
❑ Story: Save our ‘Jack: the dog’!
❑ Intro to the ‘Case study approach’
❑ Matlab Programming:
✓ Data Input and Output
✓ Decision Making
✓ Loops
✓ Functions
✓ ‘Jack is back’!
❑ What’s next?
❑ Competitive Programming
✓ Syntax: Variables and Operators
✓ Arrays + Vector + Matrix
✓ Important Commands
✓ M Files
✓ Strings
Learning Matlab: A Case Study approach
3
© EEE Makers Hub, EEE, KUET
Matlab? Why I will even bother to learn it?
MATLAB (matrix laboratory) is a fourth-generation high-level
programming language and interactive environment for numerical
computation, visualization and programming.
▪ Dealing with Matrices and Arrays
▪ 2-D and 3-D Plotting and graphics
▪ Linear Algebra
▪ Algebraic Equations
▪ Non-linear Functions
▪ Statistics
▪ Data Analysis
▪ Calculus and Differential Equations
▪ Numerical Calculations
▪ Integration
▪ Transforms
▪ Curve Fitting
▪ Various other special functions
Features
Learning Matlab: A Case Study approach
4
© EEE Makers Hub, EEE, KUET
Matlab? Why I will even bother to learn it?
“MATLAB® (matrix laboratory) is a programming platform designed
specifically for engineers and scientists”
- Mathworks
▪ Signal Processing and Communications
▪ Image and Video Processing
▪ Control Systems
▪ Test and Measurement
▪ Computational Finance
▪ Computational Biology
Application fields
Learning Matlab: A Case Study approach
5
© EEE Makers Hub, EEE, KUET
Target audience
Attributes:
▪ Zero prior experience with Matlab Programming (M. P.)
▪ want to revise some basics
▪ ONLY interested in knowing how M. P. works
▪ I hate code and Matlab, but Hey! Let’s waste some time!
If you are:
▪ One with advance knowledge of M. P.
▪ Looking for intrique/complex problems and solutions
▪ Subject specific and competitive programming
WELCOME
Don’t waste your VALUABLE time
Learning Matlab: A Case Study approach
6
© EEE Makers Hub, EEE, KUET
Save our ‘Jack: the dog’!
Storyline:
Jack: the dog had been kidnapped by a terrorist group from the KUET campus
yesterday when it was spending some quality time in the lonesome central
field. This morning the ‘Makers Hub team’ has received an anonymous letter
that prescribes a direction to locate the exact position of the terrorist gang.
Only Matlab Programmers can save Jack!
To save Jack one needs to follow the following steps:
1) Print the statement ‘Jack is missing’ to spread the news to all kuetians.
2) Ask honorable V.C. sir for permission. Remember sir will only permit if the dog is a ‘good dog’
and it’s age is more than 2 years.
3) There is a maze with 2 different routes that leads to the cave of the terrorist. Remember
the cave is ‘red colored’, and if there is a ‘blue colored’ cave you will have to ignore it.
4) Finally, you will have to build a testimony so that each time any kuetian gives his ‘KUET roll
no’ and ‘batch name’ the terrorist will say ‘We are the Worst. Forgive us!’
Learning Matlab: A Case Study approach
7
© EEE Makers Hub, EEE, KUET
‘Case study approach’
Guys! “I have just executed ‘for loop’ with 10 conditions within it.”
VS.
Guys! “I have just executed ‘for loop’ with 10 conditions within it. And it can
solely be used for calculating your gpa from your subject scores!”
Each coding exercise, however small let it be, should have a definitive purpose
It should be your nano project
CASE
STUDY
Case Output
Learning Matlab: A Case Study approach
8
© EEE Makers Hub, EEE, KUET
Syntax: Variables and Operators
No need to define ‘Variable data type (whether int or float or others)’ !
Syntax: var1 + var2 ! Addition of var1 and var2
var1 > var2 ! var2 is greater than var2
var1 <= var2 ! var1 is less than or equal to var2
var1 / var2 ! Left division: divide var1 by var2
var1  var2 ! Right division: divide var2 by var1
var1 ~= var2 ! Var1 is not equal to var2
More on the topic:
https://www.tutorialspoint.com/matlab/matlab_syntax.htm
https://www.tutorialspoint.com/matlab/matlab_variables.htm
https://www.tutorialspoint.com/matlab/matlab_operators.htm
Operators
var4= (var2 * var3) / var5 !assign & show value
var4= (var2 * var3) / var5; !assign & hide value
Semicolon to hide value
• All arrays are assigned by [ ] square brackets
• Rows are separated by comma ( , )
• Columns are separated by semicolon ( ; )
• For a X array, X(p) refers to the p th element of X array
• For a X matrix, X(r,c) refers to the matrix element which is in the r th row and
c th column
• For a X matrix, X([p : r], d) refers to the d th column of the row p to r
• If X, Y and Z are 3 arrays with similar dimensions, then
D= [ X Y Z] will concatenate all the three to one D matrix
More on the topic:
https://www.tutorialspoint.com/matlab/matlab_arrays.htm
https://www.tutorialspoint.com/matlab/matlab_matrics.htm
https://www.tutorialspoint.com/matlab/matlab_vectors.htm
Learning Matlab: A Case Study approach
9
© EEE Makers Hub, EEE, KUET
Arrays + Vector + Matrix
All variables of all data types in MATLAB are multidimensional arrays
1D Array =
Vector
2D Array = 2D
Matrix
3D Array = 3D
Matrix
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET 10
Arrays + Vector + Matrix
Matrix operation:
Mat1 + Mat2 ! Matrix addition
Mat1 * Mat2 ! Matrix multiplication
( . ) refers to element by element
Mat1 .* Mat2 ! Element by element multiplication of Mat1 and Mat2
Mat’ ! ( ‘ ) refers to transpose (row <-> column) of the matrix
Matrix function:
det(mat3) ! Determinant of mat3
inv(mat3) ! Inverse of mat3
zeros(k) ! Creates k by k matrix with each element being 0
ones(k, v) ! Creates k by v matrix with each element being 1
eye(k) ! Creates k by k identity matrix
Magic(k) ! Creates k by k magic matrix
rand(k,v) ! Creates k by v matrix with random numbers betn 0 to 1
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Important Commands
11
Commands:
clc !Clears command window
clear !Removes variables from memory/workspace
format short !Four decimal digits (default)
format long !16 decimal digits
pwd !Displays current directory
what !Lists all MATLAB files in the current directory
tik……..tok !displays the execution time of code within tik and tok
cat !Concatenates arrays
More on the topic:
https://www.tutorialspoint.com/matlab/matlab_commands.htm
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
M Files
12
Create .M file:
1. Manually using Matlab IDE
2. From command window
Matlab editor widow -> Open untitle file -> save
as -> your targeted directory
Command window:
edit !will open editor window
edit newfile.m !will create newfile.m file
mkdir mp !will create a new mp folder
Two ways:
▪ Matlab uses .m extension for scripting (automates the
execution of tasks). With one click run multiple commnad
• String is assigned by ( ‘ ‘ )
My_string= ‘This is my string’ ! Reads a string
length(My_string) ! Will print no of character with spaces in the
! string
My_string(p) ! Will display p th element of the string
strcat(a , b) ! Will add string a with string b
strcat(‘Hello’ , My_string) ! Will add ‘Hello’ with My_string
strcmp(str1 , str2) ! Will compare str1 and str2, if two are same
! Then returns 1, if not same returns 0
lower(str1) ! Convert string to lower
upper(str2) ! Convert string to upper
More on the topic:
https://www.tutorialspoint.com/matlab/matlab_strings.htm
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Strings
13
String syntax:
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Data Input and Output
14
Data input:
x = input(prompt) !shows prompt and wait for a input
str = input(prompt,'s’) !shows prompt and wait for a input and
!takes input as a string
Data imput:
Data=xlsread('name.xls') !imports data from name.xls (Excel data)
load count.dat !text file saved as .dat extenson. Matlab
!reads this and save the file in a variable
!named same as filename (here, ‘count’)
Data output:
num_array = [ 1 2 3 4 ; 4 5 6 7; 7 8 9 0];
save array_data1.out num_array -ascii; ! ASCII data file created
type array_data1.out
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Decision Making
15
Decision:
If false Conditional
statement
condition
If true
2 ways:
1. If …elseif….else…..end
2. switch…case…otherwise….end
switch <switch_expression>
case <case_expression>
<statements>
case <case_expression>
<statements>
...
...
otherwise
<statements>
end
if <condition 1>
<statement(s)>
elseif <condition 2>
<statement(s)>
elseif <condition 3>
<statement(s)>
….
….
else
<statement(s)>
end
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Loops
16
Iterating:
If false
Conditional
statement
condition
If true
2 ways:
1. for loop
2. while loop
for <loop statement>
<program statements>
...
...
end
while (loop statement)
<program statements>
...
...
end
<loop statement>
• start_value : step_size : end_value
• conditional
<break statement>
• Breaks the loop
<continue statement>
• Ignores that
iteration
• A specific conditional (if…..end) part is added to
use ‘break’ or ‘continue’ operation
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Functions
17
Functions:
3 types:
1. Built in function : sum(a , b)
2. Anonymous/inline fuction: f = @(arglist)expression
3. User defined function:
function [out1,..., outN] = myfun(in1, ..., inN)
Returned output Given input
User defined function name
Call function: myfun(in1, …., inN)
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
‘Jack is back’!
18
Good for
beginners
▪ Reference: https://www.tutorialspoint.com/matlab/index.htm
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
What’s next?
19
Advance works:
▪ Congrates! You can now dive into more Sophisticated works with Matlab
Plotting curve Algebric Equations Differentiation
Integration Calculus Polynomials
Laplace and Fourier
transform
Machine Learning +
Neural Network
Simulink : Simulation
and System Desin
Not
the
best
▪ Best resources: Mathworks Website and Matlab ‘Help’
▪ Best practices: Matlab Cody Challenge
Learning Matlab: A Case Study approach
© EEE Makers Hub, EEE, KUET
Competitive Programming
20
Given Problem Statement/ Case
Step 1
Your code/program
Step 3
Judge Function
Step 4
Your scratch algorithm
Step 2
Find the inner product of two vectors
by using a function name ‘ inner ’.
What is inner product?
If x=[1 2 3], y= [4 5 6]
Then inner product? -> dot product
function z = inner(x,y)
z = dot (x , y);
end
x = 1 : 3 ;
y= 3 : -1 : 1;
z_correct = 10 ;
assert(isequal(inner(x,y), z_correct))
Learning Matlab: A Case Study approach
21
© EEE Makers Hub, EEE, KUET
Thank you all

More Related Content

What's hot

JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
JSpiders Basavanagudi
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
 
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O MechanismsJava Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
Subhadra Sundar Chakraborty
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
Mudit Gupta
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
Garuda Trainings
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Wrapper classes
Wrapper classes Wrapper classes
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in Java
PawanMM
 
Statistical Machine Learning for Text Classification with scikit-learn and NLTK
Statistical Machine Learning for Text Classification with scikit-learn and NLTKStatistical Machine Learning for Text Classification with scikit-learn and NLTK
Statistical Machine Learning for Text Classification with scikit-learn and NLTKOlivier Grisel
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
mhtspvtltd
 
The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189
Mahmoud Samir Fayed
 
Practice Session
Practice Session Practice Session
Practice Session
Hitesh-Java
 
Towards a theory of data entangelement
Towards a theory of data entangelementTowards a theory of data entangelement
Towards a theory of data entangelementAleksandr Yampolskiy
 

What's hot (20)

JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
 
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O MechanismsJava Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in Java
 
Statistical Machine Learning for Text Classification with scikit-learn and NLTK
Statistical Machine Learning for Text Classification with scikit-learn and NLTKStatistical Machine Learning for Text Classification with scikit-learn and NLTK
Statistical Machine Learning for Text Classification with scikit-learn and NLTK
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189
 
Practice Session
Practice Session Practice Session
Practice Session
 
Towards a theory of data entangelement
Towards a theory of data entangelementTowards a theory of data entangelement
Towards a theory of data entangelement
 
07slide
07slide07slide
07slide
 
M C6java2
M C6java2M C6java2
M C6java2
 

Similar to Matlab programming

Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
Austin Baird
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
Tribhuwan Pant
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
INTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.pptINTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.ppt
Karthik537368
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
aboma2hawi
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
RaviMuthamala1
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
Smee Kaem Chann
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
محمدعبد الحى
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
VidhyaSenthil
 
programming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptxprogramming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptx
aboma2hawi
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
aibad ahmed
 
How to make fewer errors at the stage of code writing. Part N3.
How to make fewer errors at the stage of code writing. Part N3.How to make fewer errors at the stage of code writing. Part N3.
How to make fewer errors at the stage of code writing. Part N3.
PVS-Studio
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Bhavesh Shah
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
AlbanLevy
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code Clinic
Mike Acton
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
Tony Albrecht
 

Similar to Matlab programming (20)

Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
INTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.pptINTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.ppt
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Ot performance webinar
Ot performance webinarOt performance webinar
Ot performance webinar
 
programming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptxprogramming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptx
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
How to make fewer errors at the stage of code writing. Part N3.
How to make fewer errors at the stage of code writing. Part N3.How to make fewer errors at the stage of code writing. Part N3.
How to make fewer errors at the stage of code writing. Part N3.
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code Clinic
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
 

More from Md. Rayid Hasan Mojumder

Epitaxial growth - Fabrication
Epitaxial growth - FabricationEpitaxial growth - Fabrication
Epitaxial growth - Fabrication
Md. Rayid Hasan Mojumder
 
Main building
Main buildingMain building
Frequency Shit Keying(FSK) modulation project report
Frequency Shit Keying(FSK) modulation project reportFrequency Shit Keying(FSK) modulation project report
Frequency Shit Keying(FSK) modulation project report
Md. Rayid Hasan Mojumder
 
Practical appearance of machines in industry
Practical appearance of machines in industryPractical appearance of machines in industry
Practical appearance of machines in industry
Md. Rayid Hasan Mojumder
 
Three Phase Induction Motor Design
Three Phase Induction Motor DesignThree Phase Induction Motor Design
Three Phase Induction Motor Design
Md. Rayid Hasan Mojumder
 
Distribution Transformer Design (Electrical Machine Design)
Distribution Transformer Design (Electrical Machine Design)Distribution Transformer Design (Electrical Machine Design)
Distribution Transformer Design (Electrical Machine Design)
Md. Rayid Hasan Mojumder
 

More from Md. Rayid Hasan Mojumder (6)

Epitaxial growth - Fabrication
Epitaxial growth - FabricationEpitaxial growth - Fabrication
Epitaxial growth - Fabrication
 
Main building
Main buildingMain building
Main building
 
Frequency Shit Keying(FSK) modulation project report
Frequency Shit Keying(FSK) modulation project reportFrequency Shit Keying(FSK) modulation project report
Frequency Shit Keying(FSK) modulation project report
 
Practical appearance of machines in industry
Practical appearance of machines in industryPractical appearance of machines in industry
Practical appearance of machines in industry
 
Three Phase Induction Motor Design
Three Phase Induction Motor DesignThree Phase Induction Motor Design
Three Phase Induction Motor Design
 
Distribution Transformer Design (Electrical Machine Design)
Distribution Transformer Design (Electrical Machine Design)Distribution Transformer Design (Electrical Machine Design)
Distribution Transformer Design (Electrical Machine Design)
 

Recently uploaded

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 

Recently uploaded (20)

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 

Matlab programming

  • 1. © EEE Makers Hub, EEE, KUET © EEE Makers Hub, EEE, KUET A Case Study Approach Learning Created by: Md. Rayid Hasan Mojumder | EEE 2k15 | KUET
  • 2. Learning Matlab: A Case Study approach 2 © EEE Makers Hub, EEE, KUET Outline ❑ Matlab? Why I will even bother to learn it? ❑ Target audience ❑ Story: Save our ‘Jack: the dog’! ❑ Intro to the ‘Case study approach’ ❑ Matlab Programming: ✓ Data Input and Output ✓ Decision Making ✓ Loops ✓ Functions ✓ ‘Jack is back’! ❑ What’s next? ❑ Competitive Programming ✓ Syntax: Variables and Operators ✓ Arrays + Vector + Matrix ✓ Important Commands ✓ M Files ✓ Strings
  • 3. Learning Matlab: A Case Study approach 3 © EEE Makers Hub, EEE, KUET Matlab? Why I will even bother to learn it? MATLAB (matrix laboratory) is a fourth-generation high-level programming language and interactive environment for numerical computation, visualization and programming. ▪ Dealing with Matrices and Arrays ▪ 2-D and 3-D Plotting and graphics ▪ Linear Algebra ▪ Algebraic Equations ▪ Non-linear Functions ▪ Statistics ▪ Data Analysis ▪ Calculus and Differential Equations ▪ Numerical Calculations ▪ Integration ▪ Transforms ▪ Curve Fitting ▪ Various other special functions Features
  • 4. Learning Matlab: A Case Study approach 4 © EEE Makers Hub, EEE, KUET Matlab? Why I will even bother to learn it? “MATLAB® (matrix laboratory) is a programming platform designed specifically for engineers and scientists” - Mathworks ▪ Signal Processing and Communications ▪ Image and Video Processing ▪ Control Systems ▪ Test and Measurement ▪ Computational Finance ▪ Computational Biology Application fields
  • 5. Learning Matlab: A Case Study approach 5 © EEE Makers Hub, EEE, KUET Target audience Attributes: ▪ Zero prior experience with Matlab Programming (M. P.) ▪ want to revise some basics ▪ ONLY interested in knowing how M. P. works ▪ I hate code and Matlab, but Hey! Let’s waste some time! If you are: ▪ One with advance knowledge of M. P. ▪ Looking for intrique/complex problems and solutions ▪ Subject specific and competitive programming WELCOME Don’t waste your VALUABLE time
  • 6. Learning Matlab: A Case Study approach 6 © EEE Makers Hub, EEE, KUET Save our ‘Jack: the dog’! Storyline: Jack: the dog had been kidnapped by a terrorist group from the KUET campus yesterday when it was spending some quality time in the lonesome central field. This morning the ‘Makers Hub team’ has received an anonymous letter that prescribes a direction to locate the exact position of the terrorist gang. Only Matlab Programmers can save Jack! To save Jack one needs to follow the following steps: 1) Print the statement ‘Jack is missing’ to spread the news to all kuetians. 2) Ask honorable V.C. sir for permission. Remember sir will only permit if the dog is a ‘good dog’ and it’s age is more than 2 years. 3) There is a maze with 2 different routes that leads to the cave of the terrorist. Remember the cave is ‘red colored’, and if there is a ‘blue colored’ cave you will have to ignore it. 4) Finally, you will have to build a testimony so that each time any kuetian gives his ‘KUET roll no’ and ‘batch name’ the terrorist will say ‘We are the Worst. Forgive us!’
  • 7. Learning Matlab: A Case Study approach 7 © EEE Makers Hub, EEE, KUET ‘Case study approach’ Guys! “I have just executed ‘for loop’ with 10 conditions within it.” VS. Guys! “I have just executed ‘for loop’ with 10 conditions within it. And it can solely be used for calculating your gpa from your subject scores!” Each coding exercise, however small let it be, should have a definitive purpose It should be your nano project CASE STUDY Case Output
  • 8. Learning Matlab: A Case Study approach 8 © EEE Makers Hub, EEE, KUET Syntax: Variables and Operators No need to define ‘Variable data type (whether int or float or others)’ ! Syntax: var1 + var2 ! Addition of var1 and var2 var1 > var2 ! var2 is greater than var2 var1 <= var2 ! var1 is less than or equal to var2 var1 / var2 ! Left division: divide var1 by var2 var1 var2 ! Right division: divide var2 by var1 var1 ~= var2 ! Var1 is not equal to var2 More on the topic: https://www.tutorialspoint.com/matlab/matlab_syntax.htm https://www.tutorialspoint.com/matlab/matlab_variables.htm https://www.tutorialspoint.com/matlab/matlab_operators.htm Operators var4= (var2 * var3) / var5 !assign & show value var4= (var2 * var3) / var5; !assign & hide value Semicolon to hide value
  • 9. • All arrays are assigned by [ ] square brackets • Rows are separated by comma ( , ) • Columns are separated by semicolon ( ; ) • For a X array, X(p) refers to the p th element of X array • For a X matrix, X(r,c) refers to the matrix element which is in the r th row and c th column • For a X matrix, X([p : r], d) refers to the d th column of the row p to r • If X, Y and Z are 3 arrays with similar dimensions, then D= [ X Y Z] will concatenate all the three to one D matrix More on the topic: https://www.tutorialspoint.com/matlab/matlab_arrays.htm https://www.tutorialspoint.com/matlab/matlab_matrics.htm https://www.tutorialspoint.com/matlab/matlab_vectors.htm Learning Matlab: A Case Study approach 9 © EEE Makers Hub, EEE, KUET Arrays + Vector + Matrix All variables of all data types in MATLAB are multidimensional arrays 1D Array = Vector 2D Array = 2D Matrix 3D Array = 3D Matrix
  • 10. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET 10 Arrays + Vector + Matrix Matrix operation: Mat1 + Mat2 ! Matrix addition Mat1 * Mat2 ! Matrix multiplication ( . ) refers to element by element Mat1 .* Mat2 ! Element by element multiplication of Mat1 and Mat2 Mat’ ! ( ‘ ) refers to transpose (row <-> column) of the matrix Matrix function: det(mat3) ! Determinant of mat3 inv(mat3) ! Inverse of mat3 zeros(k) ! Creates k by k matrix with each element being 0 ones(k, v) ! Creates k by v matrix with each element being 1 eye(k) ! Creates k by k identity matrix Magic(k) ! Creates k by k magic matrix rand(k,v) ! Creates k by v matrix with random numbers betn 0 to 1
  • 11. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Important Commands 11 Commands: clc !Clears command window clear !Removes variables from memory/workspace format short !Four decimal digits (default) format long !16 decimal digits pwd !Displays current directory what !Lists all MATLAB files in the current directory tik……..tok !displays the execution time of code within tik and tok cat !Concatenates arrays More on the topic: https://www.tutorialspoint.com/matlab/matlab_commands.htm
  • 12. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET M Files 12 Create .M file: 1. Manually using Matlab IDE 2. From command window Matlab editor widow -> Open untitle file -> save as -> your targeted directory Command window: edit !will open editor window edit newfile.m !will create newfile.m file mkdir mp !will create a new mp folder Two ways: ▪ Matlab uses .m extension for scripting (automates the execution of tasks). With one click run multiple commnad
  • 13. • String is assigned by ( ‘ ‘ ) My_string= ‘This is my string’ ! Reads a string length(My_string) ! Will print no of character with spaces in the ! string My_string(p) ! Will display p th element of the string strcat(a , b) ! Will add string a with string b strcat(‘Hello’ , My_string) ! Will add ‘Hello’ with My_string strcmp(str1 , str2) ! Will compare str1 and str2, if two are same ! Then returns 1, if not same returns 0 lower(str1) ! Convert string to lower upper(str2) ! Convert string to upper More on the topic: https://www.tutorialspoint.com/matlab/matlab_strings.htm Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Strings 13 String syntax:
  • 14. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Data Input and Output 14 Data input: x = input(prompt) !shows prompt and wait for a input str = input(prompt,'s’) !shows prompt and wait for a input and !takes input as a string Data imput: Data=xlsread('name.xls') !imports data from name.xls (Excel data) load count.dat !text file saved as .dat extenson. Matlab !reads this and save the file in a variable !named same as filename (here, ‘count’) Data output: num_array = [ 1 2 3 4 ; 4 5 6 7; 7 8 9 0]; save array_data1.out num_array -ascii; ! ASCII data file created type array_data1.out
  • 15. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Decision Making 15 Decision: If false Conditional statement condition If true 2 ways: 1. If …elseif….else…..end 2. switch…case…otherwise….end switch <switch_expression> case <case_expression> <statements> case <case_expression> <statements> ... ... otherwise <statements> end if <condition 1> <statement(s)> elseif <condition 2> <statement(s)> elseif <condition 3> <statement(s)> …. …. else <statement(s)> end
  • 16. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Loops 16 Iterating: If false Conditional statement condition If true 2 ways: 1. for loop 2. while loop for <loop statement> <program statements> ... ... end while (loop statement) <program statements> ... ... end <loop statement> • start_value : step_size : end_value • conditional <break statement> • Breaks the loop <continue statement> • Ignores that iteration • A specific conditional (if…..end) part is added to use ‘break’ or ‘continue’ operation
  • 17. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Functions 17 Functions: 3 types: 1. Built in function : sum(a , b) 2. Anonymous/inline fuction: f = @(arglist)expression 3. User defined function: function [out1,..., outN] = myfun(in1, ..., inN) Returned output Given input User defined function name Call function: myfun(in1, …., inN)
  • 18. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET ‘Jack is back’! 18
  • 19. Good for beginners ▪ Reference: https://www.tutorialspoint.com/matlab/index.htm Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET What’s next? 19 Advance works: ▪ Congrates! You can now dive into more Sophisticated works with Matlab Plotting curve Algebric Equations Differentiation Integration Calculus Polynomials Laplace and Fourier transform Machine Learning + Neural Network Simulink : Simulation and System Desin Not the best ▪ Best resources: Mathworks Website and Matlab ‘Help’ ▪ Best practices: Matlab Cody Challenge
  • 20. Learning Matlab: A Case Study approach © EEE Makers Hub, EEE, KUET Competitive Programming 20 Given Problem Statement/ Case Step 1 Your code/program Step 3 Judge Function Step 4 Your scratch algorithm Step 2 Find the inner product of two vectors by using a function name ‘ inner ’. What is inner product? If x=[1 2 3], y= [4 5 6] Then inner product? -> dot product function z = inner(x,y) z = dot (x , y); end x = 1 : 3 ; y= 3 : -1 : 1; z_correct = 10 ; assert(isequal(inner(x,y), z_correct))
  • 21. Learning Matlab: A Case Study approach 21 © EEE Makers Hub, EEE, KUET Thank you all