0% found this document useful (0 votes)
7 views

Matlab Chapter 1

This document outlines a course on computer programming for engineers using MATLAB. The course objectives are to describe computer programming terminology and write and run MATLAB programs. It meets for 2 hours of lectures and 2 hours of labs/tutorials per week. Content includes programming fundamentals, interactive and structured MATLAB programming. Assessment is through quizzes, assignments, midterm and final exams. References provided are MATLAB books. Key programming concepts like compilers, interpreters, and MATLAB programming are also defined.

Uploaded by

peprahkofi05
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)
7 views

Matlab Chapter 1

This document outlines a course on computer programming for engineers using MATLAB. The course objectives are to describe computer programming terminology and write and run MATLAB programs. It meets for 2 hours of lectures and 2 hours of labs/tutorials per week. Content includes programming fundamentals, interactive and structured MATLAB programming. Assessment is through quizzes, assignments, midterm and final exams. References provided are MATLAB books. Key programming concepts like compilers, interpreters, and MATLAB programming are also defined.

Uploaded by

peprahkofi05
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
You are on page 1/ 20

ME 168 (COMPUTER

PROGRAMMING FOR ENGINEERS)

Dr. G.F.K. Tay

COLLEGE OF ENGINEERING
KNUST

1
Course Outline
 Course Objectives
• To describe and explain some basic terminology used
in computer programming
• To write and run computer programs in MATLAB

 Contact Hours
• Lectures (2 hrs)
• LAB / Tutorials (2 hrs)

2
Course Outline
 Course Content
• Computer Programming Fundamentals
• Interactive MATLAB Programming
• Structured MATLAB Programming

 Assessment
• Quizzes, Assignments, Mid-Semester, Final Exams

3
Assessment
• Quizzes, Assignments S1 = 30%
• Attendance
• End of Semester Exams (S2 = 70%)
• Final Score = S1 + S2

4
References
• Chapra, S.C., Applied Numerical Methods with
MATLAB for Engineers and Scientists, 3rd Int.
Ed., 2012
• Nakamura, S., Numerical Analysis and
Graphic Visualization with MATLAB, Prentice
Hall Inc. 1996

5
Computer Programming
Some Definitions
 Computer Programming:
The process of creating a computer program
 Computer Program:
A set of instructions that can be executed by
the computer to perform a specific task

 Computer Software
A set of computer programs
6
Programming Languages
A programming language is a set of commands,
instructions, and other syntax used to create a computer
program (or software).

 Programming languages can be grouped into three


main categories
• Machine languages
• Assembly languages
• High-level languages
7
Types of Programming Languages
1) Machine Languages: Machine language is the
computer’s native language, which is used to directly
control the CPU. It consists of a set of built-in primitive
instructions in the form of binary code (0s and 1s).
• Machine languages are defined by hardware design
• Disadvantages
 Programming in machine language is tedious
 Codes written in machine language are difficult to read
and modify 8
2) Assembly Languages: Assembly language uses short
descriptive words called mnemonics to represent the
machine language instructions.
• Each assembly language instruction corresponds to an
instruction in machine language
• It is easier to code in assembly than machine language
• Disadvantages
 It is machine dependent
 Still tedious to write code in assembly language
 Requires understanding of how the CPU works 9
3) High-Level Languages: These are programming
languages that allow computer programs to be written
using natural human languages.
• Examples
 Fortran
 Pascal
 C/C++
 Java
 Python
 MATLAB 10
High-Level Programming Languages

• Advantages over low-level languages


 They are English-like and easy to learn and use
 They are platform-independent
 Do not require knowledge of the CPU architecture
• High-level languages can be divided into two types:
Compiled and Interpreted programming languages

11
Compiled and Interpreted High-Level Languages
• A program written in a high-level language is called a source
program or source code
• A compiled language uses a tool known as a compiler to convert
the source code into machine code
 A compiler translates the entire source code into a machine-
code file
• An interpreted language uses an interpreter to convert the
source code into machine code
 An interpreter reads one statement from the source code,
translates it to machine code and then executes it right away
12
Classification of High-Level Languages
Language Uses a Compiler Uses an Interpreter
Pascal 
FORTRAN 
Visual Basic 
C 
C++ 
C# 
Java 
MATLAB 
Python 
Perl 
Julia 
Ruby  13
MATLAB Programming
• MATLAB stands for MATrix LABoratory
• MATLAB was invented by Cleve Moler in the late 1970s
• MATLAB is written in C.
• MATLAB works as an interpreter
• MATLAB codes run slower than codes written in C/C++ and
FORTRAN
• Uses of MATLAB
 For Data Analysis
 For developing algorithms
 For creating models and applications 14
MATLAB Programming
• MATLAB is a multi-disciplinary tool
• Can be used in Numerical Computation Applications
• Has over 90 Toolboxes in multiple fields
 Mathematics (Symbolic Math, Statistics, Curve Fitting, etc)
 Communications & Signal Processing
 Machine Vision (Image Processing, Computer Vision)
 Statistics and Regression Analysis
 Computational Finance
 Instrument Control, Vehicle Dynamics, Aerospace, etc
15
MATLAB 2019 User Interface
Command
Window

Current
Folder

Workspace

16
Some Basic MATLAB Commands
who
Lists the names of the variables defined by the user

whos
Lists detailed information about the variables defined by
the user

clc
Clears the command window
17
Some Basic MATLAB Commands
clear
Deletes all the variables from the MATLAB workspace

clear <variable name>


Deletes a certain variable
clearvars
Same as clear but more stable
beep
Produce a beep sound 18
Some Basic MATLAB Commands
date
Shows the current system date

disp (<variable name>)


Displays the value of the variable
disp (<string constant>)
Displays the string constant
ans
Automatically created variable assigned to a result 19
Interactive MATLAB Programming
• MATLAB works primarily (almost exclusively) with matrices
• MATLAB has built-in mathematical functions that are optimized
to handle matrix operations
• MATLAB can handle up to 13-Dimensional matrices

What is a Matrix?
• A matrix is a one- or multi-dimensional array of elements
• All data in MATLAB are viewed as matrices
• Thus, a scalar is a matrix with only one row and one column
• A vector contains only one row or one column 20

You might also like