0% found this document useful (0 votes)
40 views21 pages

Technical Computing 3

This document summarizes key aspects of technical computing in MATLAB, including: 1. MATLAB can operate in interactive mode or by running script files containing commands. Script files allow automated execution of commands and avoid retyping procedures. 2. Programming in MATLAB is done by writing script files (m-files) that can include relational operators, conditional statements, and loops. Relational operators allow comparisons between arrays. 3. Debugging script files involves finding and fixing syntax errors and runtime errors. Suggested script file structure includes comment, input, calculation, and output sections for improved programming style.

Uploaded by

ismail31004
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views21 pages

Technical Computing 3

This document summarizes key aspects of technical computing in MATLAB, including: 1. MATLAB can operate in interactive mode or by running script files containing commands. Script files allow automated execution of commands and avoid retyping procedures. 2. Programming in MATLAB is done by writing script files (m-files) that can include relational operators, conditional statements, and loops. Relational operators allow comparisons between arrays. 3. Debugging script files involves finding and fixing syntax errors and runtime errors. Suggested script file structure includes comment, input, calculation, and output sections for improved programming style.

Uploaded by

ismail31004
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

TECHNICAL COMPUTING

Qasim Habib
Today’s Content

1. Script Files and Editor/Debugger

2. Programming in MATLAB

3. Relational operators
Script Files and
Editor/Debugger
MATLAB operates in two ways
1.Interactive mode
2.Script files
Script Files
• Script file contains MATLAB commands, so
running it is equal to typing all the commands –
one at a time – at the command window prompt.
• You can run the file by typing its name at the
command window prompt.
• Script file variables are global variables.
Creating & using a Script
File
• Following lines show a simple script file
% Program Example.m
% This program computes the sine of
% the square root and displays the
result.
x = sqrt ( [ 5:2:13 ] )
y = sin (x)
Effective use of Script Files
• Used to avoid the need to retype
commonly used procedures.
• Names of script files should follow
the MATLAB naming conventions.
• Script file variables are global as
compared to function file variables
which are local.
Debugging Script Files
• Debugging a program is the process
of finding and removing the “bugs”,
or errors, in a program.
• Two type of errors are encountered
1.Syntax errors
2.Runtime errors
Programming Style
Suggested structure for a script file is
1.Comment Section
2.Input Section
3.Calculation Section
4.Output Section
Controlling input and output
Example of menu command
• Look the use of menu command in
the following example
Example of fprintf command
• Look the use of fprintf command in
the following example
Task 5
• Solve T1.4-2
• Study this Topic (optional)
1.5 The MATLAB Help System
Programming in MATLAB
• Programming is performed in
MATLAB using script files (m-files).
• MATLAB often uses following
capabilities in programming
1.Relational operators
2.Conditional statements
3.Loops
Relational operators
• Relational Operators are used to make
comparisons.
• MATLAB has six relational operators to
make comparisons between arrays.
• Note in the next slide that “equal to”
operator consist of two equal signs ==,
because = sign denotes ‘assignment
operator’ in MATLAB.
Some rules
• Comparison is performed on
element-by-element basis
• Arrays must be of the same
dimension
• The result of a comparison using
relational operator is a logical value,
which is either 0 (for false) or 1 (for
true).
Examples
>> x = [6,3,9] ; y = [14,2,9];
>> z = (x < y)
z =
1 0 0
>> z = (x ~= y)
z =
1 1 0
>> z = x (x < y)
z =
6
The find Function
• The function find (x) computes an array
containing the indices of the nonzero
elements of the numeric array x.
• Example
>> x = [-2 0 4]
>> y = find(x)
y =
1 3
Task 6
• Example E1.6-1
• T1.6-1 & T1.6-2
Reference
This lecture is from pg 29-46 of your main MATLAB
book

INTRODUCTION TO MATLAB 7
FOR ENGINEERS
by
WILLIAM J. PALM III

You might also like