Professional Documents
Culture Documents
Numerical Methods and - Computer Programming
Numerical Methods and - Computer Programming
COMPUTER PROGRAMMING
NOVEMBER 2021
COURSE OBJECTIVES
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
INTRODUCTION: PROGRAMMING LANGUAGES
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
MATLAB HISTORY
❑ Invented by Prof. Cleve Moler to make programming easy for his students
o Late 1970
o University of New Mexico
❑The MathWorks, Inc was formed in 1984
o By Moler and Jack Little
o One product: Matlab
❑Today
o 100 products
o Over 1,000,000 users
4
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
GETTING INTO MATLAB
Definition:
oMATLAB is a mathematical and graphical software package with
numerical, graphical, and programming capabilities.
o has built-in functions: operations, toolboxes.
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
MATLAB 2013 SYSTEM REQUIREMENT
• Operating System: Windows XP, Vista, 7 and 8
• Processor: Pentium III
• RAM: 1GB
• Hard Disk Space: 1GB for MATLAB only, 3-4GB for typical installation.
• Technical Setup Details For MATLAB 2013:
• Setup Full Size: 5.63 GB
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
MATLAB COMMAND WINDOW
o The >> in
command window
is called the
prompt.
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B 7
GETTING HELP
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
THE MATLAB DESKTOP ENVIRONMENT
o The current folder window
o The workspace
o The editor window
o The command window
Desktop Toolstrips tabs: HOME, PLOTS, APPS, EDITORS, PUBLISH, VIEW
Under these tabs: various Functional Sections are included.
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
FUNCTIONAL CATEGORICAL LIST
o Arrays and Matrices
a)“Basic Information”
b)“Operators”
c)“Operations and Manipulation”
d)“Elementary Matrices and Arrays”
e)“Specialized Matrices”
10
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
“BASIC INFORMATION”
islogical True for logical array
isempty True for empty matrix issparse True for sparse matrix
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
Examples:
A = [1 2 3; 4 5 6; 7 8 9] B = [2 4 6; 8 10 12];
Practice with those “basic functions”
C= 5.5 - 3.5i;
See what will happen to this function
isinteger (A);
a = Int8(C);
isinteger(a);
12
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
OPERATORS
+ Addition ' Transpose
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
❑See other information on functional categorical list on “Matlab
Book_V2”
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B 14
FILE I/O: OPENING, LOADING AND SAVING FILE
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
OPENING, LOADING, SAVING FILES
16
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
LOW-LEVEL FILE I/O
fclose Close one or more open files
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
TEXT FILES
csvread Read numeric data from text file, using comma delimiter
dlmread Read numeric data from text file, specifying your own
delimiter
dlmwrite Write numeric data to text file, specifying your own delimiter
textread Read data from text file, write to multiple outputs
textscan Read data from text file, convert and write to cell array
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B 18
SPREADSHEETS
Microsoft Excel Functions
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
GRAPHICS: BASIC PLOTS AND GRAPHS; ANNOTATING PLOTS;
SPECIALIZED PLOTS SYNTAXES
• 2-D graphs, specialized plots (e.g., pie charts, histograms, and contour plots),
function plotters, and Handle Graphics functions.
20
PREPARED ONLY FOR ENG HYDROLOGY AND SWC ENGINEERING STUDENTS; PREPARED BY: GIRMA B
BASIC PLOTS AND GRAPHS