SlideShare a Scribd company logo
1 of 21
Download to read offline
© 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

Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)Akshay soni
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in javaGaruda Trainings
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Yeardezyneecole
 
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in JavaPawanMM
 
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 structuresagorolabs
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset PreparationAndrew Ferlitsch
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basicsmhtspvtltd
 
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 189Mahmoud 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

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.pptKarthik537368
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptaboma2hawi
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operationsSmee Kaem Chann
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabVidhyaSenthil
 
programming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptxprogramming_tutorial_course_ lesson_1.pptx
programming_tutorial_course_ lesson_1.pptxaboma2hawi
 
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 MATLABBhavesh 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 ClinicMike Acton
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionTony 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

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

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
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
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
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
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
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
 
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
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
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
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
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
 

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