Computer Simulation Lab

Slides:



Advertisements
Similar presentations
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Physics 114: Lecture 1 Overview of Class Intro to MATLAB
Last week: We talked about: History of C Compiler for C programming
CST 1101 Problem Solving Using Computers
ECE 1304 Introduction to Electrical and Computer Engineering
ECE 1304 Introduction to Electrical and Computer Engineering
Release Numbers MATLAB is updated regularly
Chapter 1: Introduction to computers and C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Computer Programming BCT 1113
Lecture: MATLAB Chapter 1 Introduction
EGR 115 Introduction to Computing for Engineers
Basic operations in Matlab
2) Platform independent 3) Predefined functions
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Lecture 1: Introduction
Introduction to the C Language
IDENTIFIERS CSC 111.
Introduction to C++ Programming
Use of Mathematics using Technology (Maltlab)
Introduction to MATLAB
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to MATLAB
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
Introduction to Matlab:
Working with Arrays in MATLAB
Electrical and Computer Engineering Department SUNY – New Paltz
Getting Started With Coding
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Computer Simulation Lab “PPT 1 Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz

MATLAB fundamentals · Desktop, Editing ·        Variables, Operators, Expressions ·        Vectors ·        Input / Output ·        Repetition ·        Decision SUNY-New Paltz

Engineering Design SUNY-New Paltz

Types of Computer Languages Different Types of Languages: Assembly Language (Machine Specific) – Very Fast Intel 8086 Assembly Language Mac Assembly Language Texas Instrument 320TMSC5515 Assembly Language (Fast) Compiled Languages (Compiled, Machine Independent - Relatively fast) (C, C++, JAVA, C#, Fortran) Script Languages (Interpreted - (MATLAB, PHP, CAD, etc.) SUNY-New Paltz

Write a program! A Simple Program: Suppose you have $1000 saved in the bank. Interest is compounded at the rate of 9% per year. What will your bank balance be after one year? 1. Get the data (initial balance and interest rate) into the program. 2. Calculate the interest (9 per cent of $1000, i.e. $90). Add the interest to the balance ($90 + $1000, i.e. $1090) 4. Display the new balance SUNY-New Paltz

C Language #include <stdio.h> #include <stdlib.h> int main(){ double interest, balance; balance = 1000; rate = 0.09; interest = rate * balance; balance = balance + interest; printf(“balance=%d”, balance); return 0; } SUNY-New Paltz

MATLAB Program balance = 1000; rate = 0.09; interest = rate * balance; balance = balance + interest; disp( ’New balance:’ ); disp( balance ); SUNY-New Paltz

The MATLAB Desktop SUNY-New Paltz

Integrated Development Environment (IDE) q Command Window q Current Directory q Command History q Workspace SUNY-New Paltz

MATLAB Commands What is a Matlab Command? MATLAB is an interactive program. You can enter a command by typing it at the MATLAB prompt '>>' on the Command Window. help Searches for a help topic. clc Clears command window. clear Removes variables from memory. who Lists current variables. SUNY-New Paltz

Variables What is a variable in a computer language? In computer programming, a variable is a storage location paired with an associated symbolic name. SUNY-New Paltz

Examples Type: a = 5; B = -1.2345; Now look in Workspace to examine them. Type: c = 1:10; B = []; Now look in Workspace to examine them. SUNY-New Paltz

Examples Type: clear B; Type: clear SUNY-New Paltz

Variables A variable name (like balance) must comply with the following two rules: 1. It may consist only of the letters a–z, the digits 0–9 and the underscore ( _ ). 2. It must start with a letter. Valid: r2d2, pay_day Invalid: pay-day, 2a name$, _2a SUNY-New Paltz

Case sensitivity Different variables: Camel Caps: balance, BALANCE and BaLance Camel Caps: camelCaps milleniumBug dayOfTheWeek Commands are all in lower case SUNY-New Paltz

Examples of variables interest=.09; years=10; delta=1.e-3; email=‘doej@gmail.com’; vect=[1 2 3 4 5]; matx=[1 2 3; 4 5 6]; SUNY-New Paltz

Exercise Select your own symbols to express MATLAB variables for the following: 1- seconds elapsed since the start of the program. 2- Time of the day SUNY-New Paltz

workspace who: lists the names of all the variables in your workspace whos: lists the size of each variable as well ans: returns the value of the last expression evaluated but not assigned to a variable Workspace Name Size Bytes Class balance 1x1 8 double array interest 1x1 8 double array rate 1x1 8 double array SUNY-New Paltz

Exercise Using Command Window Declare a “variable” to display your name and print it with the following heading: “Name: John Doe”. Write a program that declares two variables p, q. Initialize them with the values (+3) and (-5.4), respectively. Have your program to add, subtract, multiply and divide them. SUNY-New Paltz

Arrays: vectors and matrices Initializing vectors: explicit lists x = [1 3 0 -1 5] use spaces a = [5,6,7] use commas a = [1 2 3], b = [4 5], c = [a -b] x = [ ] Initializing vectors: the colon operator x = 1:10 x = 1:0.5:4 x = 10:-1:1 x = 0:-2:-5 SUNY-New Paltz

Vector Exercises Initialize a vector (A) to have as its elements numbers 1 through 10 and another one (B) with integers -1 through -10. B. From vector C as the sum of the two vectors. C. Form vector D as the concatenation of vectors A and B. D. Display all 3 vectors side-by-side. SUNY-New Paltz

Array Subscripts r = [2, -2, 1, -4, 5, 1, 0] This gives you a row vector of seven numbers. r(3) This will display the third element of r. The number 3 is the subscript. r(2:4) This should give you the second, third and fourth elements. r(1:2:7) r([1 7 2 6]) r([1 7 2]) = [ ] will remove elements 1, 7 and 2. SUNY-New Paltz

Array Subscripts (Exercises) Form vector A made of even numbers between 0 and 12. Add the first and the last elements of the vector and call it sum1. Find sum2 as the sum of the first 4 elements of the vector. Form a new vector called B that is made of the last 4 elements of A. SUNY-New Paltz

Matrices a = [1 2 3; 4 5 6] = 1 2 3 4 5 6 a’ = 1 4 2 5 3 6 A matrix can be constructed from column vectors of the same lengths: x = 0:30:180; table = [x’ sin(x*pi/180)’] = 0.0000 0.0000 30.0000 0.5000 60.0000 0.8660 90.0000 1.0000 120.0000 0.8660 150.0000 0.5000 180.0000 0.0000 SUNY-New Paltz