CMPSC 201 Fall 2024 Lecture 21 PDF

Summary

This document is a lecture on MATLAB. It contains information on MATLAB commands, functions, operators, and saving variables. It also mentions details about Exam 2 and Project 4, and discusses the use of script files and other programming concepts.

Full Transcript

CMPSC 201- Fall 2024 Lecture 21 November 11, 2024 Exam 2  Short Answer portion has been graded for most students and the scores have been encoded on scantrons.  The scantrons have be submitted to Schreyer Institute.  Project 4 will be posted tonight. It in...

CMPSC 201- Fall 2024 Lecture 21 November 11, 2024 Exam 2  Short Answer portion has been graded for most students and the scores have been encoded on scantrons.  The scantrons have be submitted to Schreyer Institute.  Project 4 will be posted tonight. It involves C++ arrays. It will be due on 11/15.  Because the deadline for late drop is approaching, I will be posting an EXCEL spreadsheet later this week to help you determine how you are doing. MATLAB  The name is short for MATrix LABoratory.  Was designed for easy use of matrices and arrays.  Excels at numerical calculations and plotting  Is an interpreted language. MATLAB Windows  Command Window – issue commands. Simple calculations. Commands that are issues are erased when session is ended.  Current Folder Window – list contents of current folder. Default is on the X-drive. You should set it to your usb drive or the V-drive (your space on the U-drive.  Workspace Window – lists the current variables and properties of the variables.  Command History Window – keeps a list of commands given in the Command Window from session to session. Arithmetic Operators Matrix Array (or scalar) (element by element) Addition + + Subtraction - - Multiplication *.* Division /./ Left Division \.\ Exponentiation ^.^  Exponentiation has highest precedence followed by division (both left and right) and multiplication, then addition and subtraction MATLAB Variables  Variable names may be of any length, but only the first 63 characters will be used to determine uniqueness  Variable names may be comprised of letters, digits, or the underscore ( _ ).  Variable names must start with a letter.  Variables do not need to be given a data type.  All variables in MATLAB are considered to by a matrix (array) of doubles by default.  Variable names may not be a keyword.  Use the assignment operator to store values in a variable. Creating Matrices and Arrays  Enclose the values in square brackets separated by spaces, commas or both.  For systematic arrays, use colon operator, linspace function, or logspace function. Colon Operator Format – start:step:stop. If step is not given it defaults to 1. linspace function format – linspace(start, stop, number of elements). Generated values are linearly spaced between start and stop. Logspace function spaces values logarithmically in powers of 10. logspace(start, stop, number of elements)  Separate rows with semicolon (;). Formatting Commands (Table 2.2)  Specifies how values are displayed.  Does not change the value being stored. Saving Work  See list of commands issued listed in History Window  Can also create a diary  Can save variables using save command. save saves all variables listed in Workspace Window in a file with extension *.mat save variable list saves specific variables in file with extension *.mat save variable list – asci saves specific variable in ascii file that can be read by notepad, et.  Use load command to load variables that have been saved Creating Script File  Script file contains a list of commands that solve specific task(s). Can be run to repeat a series of commands.  What you will be submitting for Lab 10 and Labs 8- 10 makeup, and Project 5.  Is an asci file that can be read and modified using NOTEPAD, WORDPAD etc. Questions ???

Use Quizgecko on...
Browser
Browser