Study Notes for AME 167: Computer Programming for Engineers

AME 167: COMPUTER PROGRAMMING FOR ENGINEERS

Course Overview

  • Instructor: Dr. G.F.K. Tay
  • Institution: College of Engineering, KNUST

Course Objectives

  • Describe and explain basic terminology used in computer programming.
  • Write and run computer programs using MATLAB.

Contact Hours

  • Lectures: 4 hours per week

Course Content

  1. Computer Programming Fundamentals
  2. Interactive MATLAB Programming
  3. Structured MATLAB Programming

Assessment Criteria

  • Types of Assessments:
    • Quizzes
    • Assignments
    • Attendance
    • End of Semester Exams
  • Weightage:
    • S1 (30%): Includes quizzes and assignments
    • S2 (70%): Final exams
  • Final Score Calculation:
    • Final Score = S1 + S2

Course References

  1. Chapra, S.C. (2012). Applied Numerical Methods with MATLAB for Engineers and Scientists, 3rd Int. Ed.
  2. Nakamura, S. (1996). Numerical Analysis and Graphic Visualization with MATLAB. Prentice Hall Inc.

Computer Programming Fundamentals

Definitions

  • Computer Programming: The process of designing, writing, testing, and maintaining computer programs.
  • Computer Program: A set of instructions that can be executed by the computer to perform a specific task.
  • Computer Software: A collection of computer programs and related data.

Programming Languages

  • Definition: A programming language is a set of commands, instructions, and other syntax used to create a computer program (or software).
Categories of Programming Languages
  1. Machine Languages:

    • Definition: The computer's native language, used to control the CPU directly.
    • Characteristics:
      • Consists of binary code (0s and 1s).
      • Defined by hardware design.
    • Disadvantages:
      • Tedious programming process.
      • Difficult to read and modify.
  2. Assembly Languages:

    • Definition: Uses short descriptive words (mnemonics) to represent machine language instructions.
    • Characteristics:
      • Each instruction corresponds directly to machine language.
      • Easier to code compared to machine language.
    • Disadvantages:
      • Machine dependent.
      • Still tedious to write.
      • Requires knowledge of CPU workings.
  3. High-Level Languages:

    • Definition: Programming languages that allow the use of natural human language.
    • Examples:
      • Fortran
      • Pascal
      • C/C++
      • Java
      • Python
      • MATLAB
    • Advantages:
      • English-like syntax, easier to learn.
      • Platform-independent.
      • No need for CPU architecture knowledge.
High-Level Languages Classification
  • Compiled Languages:
    • Use a compiler to convert the source code into machine code (entire source code is translated at once).
  • Interpreted Languages:
    • Use an interpreter that translates and executes the source code one statement at a time immediately.
Example Classification of High-Level Languages
  • Uses a Compiler:
    • Pascal
    • FORTRAN
    • Visual Basic
    • C
    • C++
    • C#
    • Java
    • MATLAB
  • Uses an Interpreter:
    • Python
    • Perl
    • Julia
    • Ruby

MATLAB Programming

  • Definition: MATLAB stands for MATrix LABoratory.
  • Inventor: Cleve Moler in the late 1970s.
  • Development Language: Written in C.
  • Functionality: Works as an interpreter, but runs slower than C/C++ and FORTRAN.
  • Uses of MATLAB:
    • Data analysis
    • Developing algorithms
    • Creating models and applications
  • Characteristics:
    • Multi-disciplinary tool.
    • Numerical computation applications.
    • Over 90 toolboxes across various fields including:
    • 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.

MATLAB User Interface (2019 Version)

  • Components:
    • Command Window
    • Current Folder
  • Available Functions:
    • New Variable creation
    • Analyze Code
    • Preferences
    • Community Engagement
    • Support Requests
    • File Operations (new, open, save, compare, import)

Basic MATLAB Commands

  1. who: Lists the names of variables defined by the user.
  2. whos: Provides detailed information about the variables defined by the user.
  3. clc: Clears the command window.
  4. clear: Deletes all variables from the MATLAB workspace.
  5. clear <variable name>: Deletes a specified variable.
  6. clearvars: Same as clear, but more stable.
  7. beep: Produces a beep sound.
  8. date: Shows the current system date.
  9. disp(<variable name>): Displays the value of the specified variable.
  10. disp(<string constant>): Displays the string constant.
  11. ans: Automatically created variable assigned to the result of operations.

Interactive MATLAB Programming

  • Matrix Focus: MATLAB primarily works with matrices and has built-in functions optimized for matrix operations.
  • Matrix Definition: A matrix is defined as a one- or multi-dimensional array of elements, where all data in MATLAB are viewed as matrices.
    • A scalar in MATLAB is a matrix with one row and one column.
    • A vector is either a row or column matrix.