SlideShare a Scribd company logo
1
MATLAB Programming
2
MATLAB
a flagship software which was originally developed as a
matrix library. A variety of numerical functions, symbolic
computations, and visualization tools have been added to the
matrix manipulations.
Demo programs:
http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara.m
http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara2.m
http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara4.m
))](([)()( 11 iiiii tttv
m
c
gtvtv  
3
Sample Program
• g=9.8;
• cd=12.5;
• m = 68.1;
• dt = input('time increment (s):');
• tf = input('final time (s):');
• ti=0;
• vi=0;
• while (1)
• dvdt = g-(cd/m)*vi;
• vi = vi + dvdt*dt;
• ti = ti + dt;
• if ti >= tf, break, end
• end
• disp('velocity (m/s):')
• disp(vi)
t (sec.) V (m/s)
0 0
2 19.60
4 32.00
8 44.82
10 47.97
12 49.96
∞ 53.39
m=68.1 kg; c=12.5 kg/s; g=9.8 m/s
))](([)()( 11 iiiii tttv
m
c
gtvtv  
4
Built-in functions
sqrt(x)
exp(x)
abs(x)
log(x)
log10(x)
factorial(x)
TRIGONEMETRIC
sin(x)
sind(x)
cos(x)
cosd(x)
tan(x)
tand(x)
cot(x)
cotd(x)
Rounding functions
round(x)
fix(x) - round towards zero
ceil(x)
floor(x)
rem(x,y) – returns the remainder
after x is divided by y
(similar to % function in C)
Display formats
format short : 41.4286
format long:
41.42857142857143
format short e: 4.1429e+001
format long e:
4.142857142857143e+0001
format short g: 41.429
format long g:
41.4285714285714
format bank: 41.43
format compact: eliminates
empty lines
format loose: adds empty lines
5
Plot function
>> x=0:1:5
x =
0 1 2 3 4 5
>> y = sin(10*x) + cos(3*x)
y =
1.0000 -1.5340 1.8731 -1.8992 1.5890 -1.0221
>> plot(x,y)
>> xlabel('x in radians')
>> ylabel('y = sin(10*x) + cos(3*x)')
>>
>> z = zeros(1,6) % alternative way z=0*x
z =
0 0 0 0 0 0
>> plot(x,y, x,z)
>> xlabel('x in radians')
>> ylabel('y = sin(10*x) + cos(3*x)')
6
Roots of polynomials
>> r = [1, -2, 4]
r =
1 -2 4
>> poly(r)
ans =
1 -3 -6 8
>> p = poly(r)
p =
1 -3 -6 8
>> solve = roots(p)
solve =
4.0000
-2.0000
1.0000
System of equations
>> x=[-1, 5]
x =
-1 5
>> A = [2, 3; -1, 4]
A =
2 3
-1 4
>> b = A*x'
b =
13
21
>> solveX = inv(A)*b
solveX =
-1.0000
5.0000
**here Fundamental control structures in MATLAB
Managing Variables
clear – removes all variables from memory clear x y – removes only x and y from memory
who – displays a list of variables in the memory whos – displays a list of variables in the
memory along with their size and class
FOR-Loop sum = 0;
DOFOR i = start, step, final for i = 2:1:25
(Loop Body) sum = sum + A[i];
ENDDO end
• Spreadsheet that allows the user to enter and perform calculations on rows
and columns of data.
• When any value on the sheet is changed, entire calculation is updated,
therefore, spreadsheets are ideal for “what if?” sorts of analysis.
• Excel has some built in numerical capabilities including equation solving,
curve fitting and optimization.
• It has several visualization tools, such as graphs and three dimensional
plots.
• It also includes Visual Basic (VBA) as a macro language that can be used
to implement numerical calculations.
check out: http://www.anthony-vba.kefra.com/vba/vbabasic1.htm
EXCEL
Applied numerical methods lec2
Special Problem 2

More Related Content

What's hot (20)

PDF
Simplifying development-short - Mirco Dotta (Typesafe)
Scala Italy
 
PPTX
Basic of octave matlab programming language
Aulia Khalqillah
 
PDF
Programming withmatlab
nehanairm
 
PPTX
Seminar fp
VeerapatBoonvanich1
 
PDF
GNU octave
gauravmalav
 
PPTX
Mbd2
Mahmoud Hussein
 
PDF
MATLAB for Technical Computing
Naveed Rehman
 
PPT
Matlab1
guest8ba004
 
PPTX
Scilab presentation
Nasir Ansari
 
PPT
Matlab introduction
Satish Gummadi
 
PPTX
matlab
Farhan Ahmed
 
PDF
Matlab solved problems
Make Mannan
 
PDF
Ss matlab solved
Vijendrasingh Rathor
 
PPTX
What is matlab
Shah Rukh Qureshi
 
PDF
Matlab lec1
Amba Research
 
DOCX
B61301007 matlab documentation
Manchireddy Reddy
 
PPTX
Matlab matrices and arrays
Ameen San
 
PPTX
Lecture 8-9 block-diagram_representation_of_control_systems
Saifullah Memon
 
PPTX
2D Plot Matlab
Jorge Jasso
 
PDF
Network security CS6
Infinity Tech Solutions
 
Simplifying development-short - Mirco Dotta (Typesafe)
Scala Italy
 
Basic of octave matlab programming language
Aulia Khalqillah
 
Programming withmatlab
nehanairm
 
GNU octave
gauravmalav
 
MATLAB for Technical Computing
Naveed Rehman
 
Matlab1
guest8ba004
 
Scilab presentation
Nasir Ansari
 
Matlab introduction
Satish Gummadi
 
matlab
Farhan Ahmed
 
Matlab solved problems
Make Mannan
 
Ss matlab solved
Vijendrasingh Rathor
 
What is matlab
Shah Rukh Qureshi
 
Matlab lec1
Amba Research
 
B61301007 matlab documentation
Manchireddy Reddy
 
Matlab matrices and arrays
Ameen San
 
Lecture 8-9 block-diagram_representation_of_control_systems
Saifullah Memon
 
2D Plot Matlab
Jorge Jasso
 
Network security CS6
Infinity Tech Solutions
 

Similar to Applied numerical methods lec2 (20)

PPTX
Mat lab workshop
Vinay Kumar
 
PPTX
Matlab-1.pptx
aboma2hawi
 
PPTX
Matlab ppt
chestialtaff
 
PPT
Learn Matlab
Abd El Kareem Ahmed
 
PDF
Control Systems Engineering_MATLAB Experiments.pdf
sarosh31
 
PDF
Control Systems Engineering_MATLAB Experiments.pdf
sarosh31
 
PDF
Big datacourse
Massimiliano Ruocco
 
PPT
4413-lecture-09 Introduction Matlab lecture .ppt
aaaaboud1
 
PPT
Palm m3 chapter1b
Juan Pablo Fuentes Encinas
 
PDF
Introduction to Matlab.pdf
ssuser43b38e
 
PDF
Programming with matlab session 1
Infinity Tech Solutions
 
PPT
Chapter 1.ppt
Indra Hermawan
 
PDF
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Arnaud Joly
 
PDF
MATLAB Programming
محمدعبد الحى
 
DOCX
A practical work of matlab
SalanSD
 
PDF
22CS201 COA
Kathirvel Ayyaswamy
 
PDF
Matlab intro
Chaitanya Banoth
 
PPTX
Matlab_Harshal.pptx
HarshalGosavi8
 
PPT
R Programming Intro
062MayankSinghal
 
PPTX
MATLAB Workshop for project and research
Nuthal Srinivasan
 
Mat lab workshop
Vinay Kumar
 
Matlab-1.pptx
aboma2hawi
 
Matlab ppt
chestialtaff
 
Learn Matlab
Abd El Kareem Ahmed
 
Control Systems Engineering_MATLAB Experiments.pdf
sarosh31
 
Control Systems Engineering_MATLAB Experiments.pdf
sarosh31
 
Big datacourse
Massimiliano Ruocco
 
4413-lecture-09 Introduction Matlab lecture .ppt
aaaaboud1
 
Palm m3 chapter1b
Juan Pablo Fuentes Encinas
 
Introduction to Matlab.pdf
ssuser43b38e
 
Programming with matlab session 1
Infinity Tech Solutions
 
Chapter 1.ppt
Indra Hermawan
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Arnaud Joly
 
MATLAB Programming
محمدعبد الحى
 
A practical work of matlab
SalanSD
 
22CS201 COA
Kathirvel Ayyaswamy
 
Matlab intro
Chaitanya Banoth
 
Matlab_Harshal.pptx
HarshalGosavi8
 
R Programming Intro
062MayankSinghal
 
MATLAB Workshop for project and research
Nuthal Srinivasan
 
Ad

More from Yasser Ahmed (15)

PPT
Artificial reefs
Yasser Ahmed
 
PDF
Novel approach of bidirectional diffuser-augmented channels system for enhanc...
Yasser Ahmed
 
PDF
Applied numerical methods lec14
Yasser Ahmed
 
PDF
Applied numerical methods lec13
Yasser Ahmed
 
PDF
Applied numerical methods lec12
Yasser Ahmed
 
PDF
Applied numerical methods lec11
Yasser Ahmed
 
PDF
Applied numerical methods lec10
Yasser Ahmed
 
PDF
Applied numerical methods lec9
Yasser Ahmed
 
PDF
Applied numerical methods lec8
Yasser Ahmed
 
PDF
Applied numerical methods lec7
Yasser Ahmed
 
PDF
Applied numerical methods lec6
Yasser Ahmed
 
PDF
Applied numerical methods lec5
Yasser Ahmed
 
PDF
Applied numerical methods lec4
Yasser Ahmed
 
PDF
Applied numerical methods lec3
Yasser Ahmed
 
PDF
Applied numerical methods lec1
Yasser Ahmed
 
Artificial reefs
Yasser Ahmed
 
Novel approach of bidirectional diffuser-augmented channels system for enhanc...
Yasser Ahmed
 
Applied numerical methods lec14
Yasser Ahmed
 
Applied numerical methods lec13
Yasser Ahmed
 
Applied numerical methods lec12
Yasser Ahmed
 
Applied numerical methods lec11
Yasser Ahmed
 
Applied numerical methods lec10
Yasser Ahmed
 
Applied numerical methods lec9
Yasser Ahmed
 
Applied numerical methods lec8
Yasser Ahmed
 
Applied numerical methods lec7
Yasser Ahmed
 
Applied numerical methods lec6
Yasser Ahmed
 
Applied numerical methods lec5
Yasser Ahmed
 
Applied numerical methods lec4
Yasser Ahmed
 
Applied numerical methods lec3
Yasser Ahmed
 
Applied numerical methods lec1
Yasser Ahmed
 
Ad

Recently uploaded (20)

PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Basics of Auto Computer Aided Drafting .pptx
Krunal Thanki
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
filteration _ pre.pptx 11111110001.pptx
awasthivaibhav825
 
PDF
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
PDF
勉強会資料_An Image is Worth More Than 16x16 Patches
NABLAS株式会社
 
PPTX
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Basics of Auto Computer Aided Drafting .pptx
Krunal Thanki
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
filteration _ pre.pptx 11111110001.pptx
awasthivaibhav825
 
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Inventory management chapter in automation and robotics.
atisht0104
 
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
勉強会資料_An Image is Worth More Than 16x16 Patches
NABLAS株式会社
 
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 

Applied numerical methods lec2

  • 2. 2 MATLAB a flagship software which was originally developed as a matrix library. A variety of numerical functions, symbolic computations, and visualization tools have been added to the matrix manipulations. Demo programs: http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara.m http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara2.m http://web.mst.edu/~ercal/228/MATLAB/1-2/analpara4.m ))](([)()( 11 iiiii tttv m c gtvtv  
  • 3. 3 Sample Program • g=9.8; • cd=12.5; • m = 68.1; • dt = input('time increment (s):'); • tf = input('final time (s):'); • ti=0; • vi=0; • while (1) • dvdt = g-(cd/m)*vi; • vi = vi + dvdt*dt; • ti = ti + dt; • if ti >= tf, break, end • end • disp('velocity (m/s):') • disp(vi) t (sec.) V (m/s) 0 0 2 19.60 4 32.00 8 44.82 10 47.97 12 49.96 ∞ 53.39 m=68.1 kg; c=12.5 kg/s; g=9.8 m/s ))](([)()( 11 iiiii tttv m c gtvtv  
  • 4. 4 Built-in functions sqrt(x) exp(x) abs(x) log(x) log10(x) factorial(x) TRIGONEMETRIC sin(x) sind(x) cos(x) cosd(x) tan(x) tand(x) cot(x) cotd(x) Rounding functions round(x) fix(x) - round towards zero ceil(x) floor(x) rem(x,y) – returns the remainder after x is divided by y (similar to % function in C) Display formats format short : 41.4286 format long: 41.42857142857143 format short e: 4.1429e+001 format long e: 4.142857142857143e+0001 format short g: 41.429 format long g: 41.4285714285714 format bank: 41.43 format compact: eliminates empty lines format loose: adds empty lines
  • 5. 5 Plot function >> x=0:1:5 x = 0 1 2 3 4 5 >> y = sin(10*x) + cos(3*x) y = 1.0000 -1.5340 1.8731 -1.8992 1.5890 -1.0221 >> plot(x,y) >> xlabel('x in radians') >> ylabel('y = sin(10*x) + cos(3*x)') >> >> z = zeros(1,6) % alternative way z=0*x z = 0 0 0 0 0 0 >> plot(x,y, x,z) >> xlabel('x in radians') >> ylabel('y = sin(10*x) + cos(3*x)')
  • 6. 6 Roots of polynomials >> r = [1, -2, 4] r = 1 -2 4 >> poly(r) ans = 1 -3 -6 8 >> p = poly(r) p = 1 -3 -6 8 >> solve = roots(p) solve = 4.0000 -2.0000 1.0000 System of equations >> x=[-1, 5] x = -1 5 >> A = [2, 3; -1, 4] A = 2 3 -1 4 >> b = A*x' b = 13 21 >> solveX = inv(A)*b solveX = -1.0000 5.0000
  • 7. **here Fundamental control structures in MATLAB Managing Variables clear – removes all variables from memory clear x y – removes only x and y from memory who – displays a list of variables in the memory whos – displays a list of variables in the memory along with their size and class FOR-Loop sum = 0; DOFOR i = start, step, final for i = 2:1:25 (Loop Body) sum = sum + A[i]; ENDDO end
  • 8. • Spreadsheet that allows the user to enter and perform calculations on rows and columns of data. • When any value on the sheet is changed, entire calculation is updated, therefore, spreadsheets are ideal for “what if?” sorts of analysis. • Excel has some built in numerical capabilities including equation solving, curve fitting and optimization. • It has several visualization tools, such as graphs and three dimensional plots. • It also includes Visual Basic (VBA) as a macro language that can be used to implement numerical calculations. check out: http://www.anthony-vba.kefra.com/vba/vbabasic1.htm EXCEL