0% found this document useful (0 votes)
2 views16 pages

Introduction To Programming Using Matlab

COMP113 is an introductory programming course using MATLAB, taught by Dr. Abdullah Kendibilir at Piri Reis University. The course covers fundamental programming concepts, including data types, operators, loops, and MATLAB environment, with assessments based on a midterm and final exam. Key resources include textbooks by Stormy Attaway, Stephen J. Chapman, and Holly Moore, and the course includes weekly laboratory sessions.

Uploaded by

htanlik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Introduction To Programming Using Matlab

COMP113 is an introductory programming course using MATLAB, taught by Dr. Abdullah Kendibilir at Piri Reis University. The course covers fundamental programming concepts, including data types, operators, loops, and MATLAB environment, with assessments based on a midterm and final exam. Key resources include textbooks by Stormy Attaway, Stephen J. Chapman, and Holly Moore, and the course includes weekly laboratory sessions.

Uploaded by

htanlik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMP113 Computer Technology and Programming

Introduction to programming using MATLAB

Dr. Abdullah Kendibilir


Faculty of Engineering
Piri Reis University
akendibilir@[Link]
Schedule

Lecture:
• Friday (12:00-15:00) at A-119B Laboratory

• Friday (15:00-18:00) at A-119B Laboratory

• Recitation:
• There will be a 1-hour-long laboratory session each week.

• TAs:
▪ Sanem Deniz (sdeniz@[Link])

Assessment Criteria:
▪ %40 Midterm Exam - %60 Final Exam
COURSE TOPICS
I. Introduction to programming using MATLAB
II. Arithmetic, logical operators, mathematical expressions
III. Vector/matrix creation, manipulation, and operations
IV. Data types, Input-output operations
V. Flowcharts and pseudocode
VI. Conditional Statements: if-else-switch statements
VII. Loops: for and while loops and iteration techniques
[Link] transfer: writing and reading
IX. Plotting
X. Engineering Applications
COURSE BOOKS

Main Textbook:
I. Stormy Attaway, MATLAB: A Practical Introduction to Programming and Problem Solving,
Fourth Edition (2017), Butterworth-Heinemann. ISBN: 978-0-12-804525-1. (Main Textbook)

II. Stephen J. Chapman, MATLAB Programming for Engineers, Sixth Edition (2017), Cengage
Learning. ISBN: 978-1305445369.

III. Holly Moore, MATLAB for Engineers, Fifth Edition (2015), Pearson. ISBN: 978-0133499641.
Introduction to MATLAB
MATLAB = MATrix LABoratory: Developed for numerical computing with matrices and arrays.
Key Uses:

• Numerical computation
• Data analysis and visualization
• Algorithm development and prototyping
Advantages:
• Easy-to-use high-level language
• Built-in mathematical functions
• Powerful plotting and visualization tools

You can perform calculations, analyze data, develop algorithms, and visualize results efficiently.

One of its main advantages is the combination of easy-to-read code with powerful mathematical and
graphical capabilities.
MATLAB Environment Overview
Current Folder
• Displays the current working directory and files, easy file management
Command window
• Enter commands directly and see immediate results
Workspace
• Shows current variables and their values
Editor / Script files
• Write, save, and run scripts (.m files)
Command history
• Keeps a log of previous commands for easy reuse
Figure window
• Displays plots, graphs, and visual outputs
MATLAB Environment Overview
Editor / Script files

Current folder Editor / Script files Figure window

Command window

Workspace
First MATLAB Commands
Clearing and Resetting

• clc - Clears the Command Window

• clear - Removes all variables from the workspace

• close all - Closes all open figure windows

Arithmetic Operations

• +, - , * , / , ^ , .^

Variables

• Assign values, x=4. Variable names are case-sensitive, letters and numbers allowed, must start with a letter

Built-in Functions ( sin(x), tan(x), exp(x), sqrt(x), log(x), abs(x) )

• Examples: sqrt(25), sin(pi/2)…

Note: Putting a semicolon at the end of a statement suppresses the output. For example,
Variables and Assignment Statements

• To store a value in a MATLAB session, or in a program, a variable is used.

• The Workspace Window shows variables that have been created and their values.

• The format of an assignment statement is

• The variable is always on the left, followed by the = symbol, which is the assignment
operator

• (unlike in mathematics, the single equal sign does not mean equality), followed by an
expression.

As the equal sign is the assignment operator, and does not mean equality, the statement should
be read as "mynum gets the value of 6" (not "mynum equals 6").
Numerical Expressions
Operators

In addition to displaying numbers with decimal points, numbers can also be shown using scientific
or exponential notation.
Operator Precedence Rules
Some operators have precedence over others.

Nested parentheses are parentheses inside of others; the expression in the inner parentheses is evaluated first.

For example, in the expression 5 - (6 *(4 + 2)) , first the addition is performed, then the multiplication,
and finally the subtraction, to result in -31.

For the operators that have been covered thus far, the following is the prece dence (from the highest to the
lowest):
Constants
Variables are used to store values that might change, or for which the values are not known ahead of
time. Most languages also have the capacity to store constants, which are values that are known ahead
of time and cannot possibly change.
Random Numbers
• When a program is being written to work with data, and the data are not yet available, it
is often useful to test the program first by initializing the data variables to random
numbers.

• The function rand can be used to generate uniformly distributed random real numbers;
calling it generates one random real number in the open interval (0,1)

• As the rand function returns a real number, this can be rounded to produce a random
integer. For example,

• A better method is to use the function randi, which in its simplest form randi(imax)
returns a random integer in the range from 1 to imax, inclusive.

• For example, randi(4) returns a random integer in the range from 1 to 4. A range can
also be passed, for example, randi([imin, imax]) returns a random integer in the inclusive
range from imin to imax:
Characters and Strings

Feature Character (char) String

Syntax 'text' "text"

Data Type Character array (char array) String scalar or array (string)

Introduced in Available in all MATLAB versions Introduced in R2017a

Modern text processing and data


Best for Simple text or single symbols
analysis

Concatenation Uses brackets ['a', 'b'] Uses + operator "a" + "b"


Relational Expressions
• Expressions that are conceptually either true or false are called relational expressions; they are also sometimes
called Boolean expressions or logical expressions.

• These expressions can use both relational operators, which relate two expressions of compatible types, and logical
operators, which operate on logical operands.

• The type of the result is logical, not double. MATLAB also has built-in true and false. In other words, true is
equivalent to logical(1) and false is equivalent to logical(0).

Relational operators

Logical operators
Relational Expressions
• In addition to these logical operators, MATLAB also has a function xor, which is the exclusive or function.
It returns logical true if one (and only one) of the arguments is true.

You might also like