February 7, 2005 Lecture 7 - By Paul Lin 1 CPET 190 Lecture 7 Problem Solving with MATLAB Paul Lin

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 11 AC Circuit Power Analysis.
Lesson 20 Series AC Circuits. Learning Objectives Compute the total impedance for a series AC circuit. Apply Ohm’s Law, Kirchhoff’s Voltage Law and the.
Introduction to MATLAB
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.
Capacitors and Inductors.  A capacitor is a device that stores an electrical charge  It is made of two metallic plates separated by an insulator or.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
INC 112 Basic Circuit Analysis Week 12 Complex Power Complex Frequency.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
Resonant Circuit.
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Inductive Reactance Electronics. Inductors in AC Circuits.
Lecture 13 final part. Series RLC in alternating current The voltage in a capacitor lags behind the current by a phase angle of 90 degrees The voltage.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Introduction to Matlab Module #1 Page 1 Introduction to Matlab Module #1 – Getting Started with Matlab Topics 1.Starting a session 2.Entering commands.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
26 - 3/20/2000AME 150L1 M ATLAB ® /20/2000AME 150L2 M ATLAB ® vs. Fortran Fortran Positives –First Compiler –Legacy Codes –Efficient Numerically.
Introduction to MATLAB
Script M-Files Group of Matlab commands placed in a text file with a text editor. Matlab can open and execute the commands exactly as if they were entered.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Engineering Analysis – Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Fig 33-CO These large transformers are used to increase the voltage at a power plant for distribution of energy by electrical transmission to the power.
CSE123 Lecture 3 Files and File ManagementScripts.
Slide 1Fig 33-CO, p Slide 2Fig 33-1, p the basic principle of the ac generator is a direct consequence of Faraday’s law of induction. When.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
MATLAB Profiling Lien-Chi Lai, COLA Lab 2010/05/06.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Alternating Current Circuits. AC Sources  : angular frequency of AC voltage  V max : the maximum output voltage of AC source.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Chapter 12 RL Circuits.
Chapter 31 Alternating Current.
Single Phase System.
Lecture 03: AC RESPONSE ( REACTANCE N IMPEDANCE )
Lecture 07 AC POWER & POWER FACTOR.
AC POWER & POWER FACTOR.
MATLAB – More Script Files
Lesson 16: Series AC Circuits
AC Circuit Phasors Physics 102: Lecture 13
Introduction to Matlab
Lecture 6 (III): AC RESPONSE
Introduction to MATLAB
11/13/2018.
Problem Solving with MATLAB
Lecture 08 AC POWER ANALYSIS
Alternating Current Circuits and Electromagnetic Waves
AC circuits Physics /23/2018 Lecture XIX.
PHYS 221 Recitation Kevin Ralphs Week 8.
Lecture Outline Chapter 24 Physics, 4th Edition James S. Walker
ECE131 BASIC ELECTRICAL & ELECTRONICS ENGG
Complex Numbers in Engineering (Chapter 5 of Rattan/Klingbeil text)
C H A P T E R 13 A.C. Series Circuits.
Electrical Principles
Electrical Principles
Presentation transcript:

February 7, 2005 Lecture 7 - By Paul Lin 1 CPET 190 Lecture 7 Problem Solving with MATLAB Paul Lin

February 7, 2005 Lecture 7 - By Paul Lin 2 Lecture 7: MATLAB Built-In Functions 7-1 Managing Variables and Workspace 7-2 MATLAB Commands for Working with Files and the Operating System 7-3 Controlling Command Window 7-4 Time and Date Functions 7-5 Special Variables and Constants

February 7, 2005 Lecture 7 - By Paul Lin Managing Variables and Workspace Removing Unneeded Variables Removing Unneeded Variables who- List current variableswho- List current variables whos- List current variables, long formwhos- List current variables, long form clear- Clear variables and functionsclear- Clear variables and functions Creating New Variables Creating New Variables length- Length of vectorlength- Length of vector size- Size of matrixsize- Size of matrix Saving to and Retrieving from Disk Files Saving to and Retrieving from Disk Files load - Retrieve variables from disksload - Retrieve variables from disks save- Save workspace variables to disksave- Save workspace variables to disk pack- Consolidate workspace memorypack- Consolidate workspace memory Workspace display Workspace display disp- Display matrix or textdisp- Display matrix or text fprintffprintf

February 7, 2005 Lecture 7 - By Paul Lin Managing Variables and Workspace (continue) Example 7-1: %cpet190_ex7_1.m F = 4000; T = 1/F; dt = 0.01*T; t = 0:dt:2*T; e1 = 5*sin(2*pi*F*t); len = length(e1) size_e1 = size(e1) e2 = zeros(size(e1)); num = rand(2); fprintf('The random number array is %g\n', num); fprintf('\n'); disp('The random numbers'); disp(num); whos save ex7_1 clear load ex7_1 whos

February 7, 2005 Lecture 7 - By Paul Lin Managing Variables and Workspace Example 7-1: Output Example 7-1: Output

February 7, 2005 Lecture 7 - By Paul Lin Working with Files and OS The commands for working with files and operating system The commands for working with files and operating system CommandPurpose pwdShow present working directory cdChange current working directory dirDirectory listing (Window OS) lsDirectory Listing (Unix/Linux OS) deleteDelete file diarySave text of MATLAB session !Execute OS commands

February 7, 2005 Lecture 7 - By Paul Lin Working with Files and OS Example 7-2 Example 7-2 >> pwd ans = C:\Courses\CPET190\matlabex1 90 >> cd.. >> pwd ans = C:\Courses\CPET190 >> dir. Mlin_CPET190.. Exs QuizLectures MATLABExs Example 7-2 (cont.) Example 7-2 (cont.) >> diary >> diary off >> diary on >> !time The current time is: 11:31:05.02 Enter the new time: Enter the new time: Open diary file using MATLAB M-file editor, MS NOTEPAD, or MS Word help help

February 7, 2005 Lecture 7 - By Paul Lin Controlling the Command Window clcClear command window homeSend cursor home (upper-left corner of command window) formatSet output format moreControl paged output in command window echoEcho on/off commands inside script files, for debugging purposes

February 7, 2005 Lecture 7 - By Paul Lin Time and Date Functions FunctionPurpose dateCalendar clockSystem clock; accuracy 1/100th of a second nowCurrent date and time as serial date number datestrConvert a serial date number into the common date/time, save as a string cputimeHow many seconds the MATLAB session is active; accuracy 1/100 th of second etimeElapsed time function ticStart watch timer function tocStop watch timer function

February 7, 2005 Lecture 7 - By Paul Lin Time and Date Functions Time and Date Functions Time and Date Functions Example 7-3: >> date ans = 03-Oct-2004 >> now ans = e e+005 >> datestr(now) ans = 03-Oct :47:29 >> help datestr

February 7, 2005 Lecture 7 - By Paul Lin Time and Date Functions (continue) CLOCK Current date and time as date vector. CLOCK returns a six element date vector containing the CLOCK returns a six element date vector containing the current time and date in decimal form: current time and date in decimal form: CLOCK = [year month day hour minute seconds] CLOCK = [year month day hour minute seconds] The first five elements are integers. The seconds element The first five elements are integers. The seconds element is accurate to several digits beyond the decimal point. is accurate to several digits beyond the decimal point. FIX(CLOCK) rounds to integer display format. FIX(CLOCK) rounds to integer display format.Example: >> clock ans = 1.0e+003 * 1.0e+003 *

February 7, 2005 Lecture 7 - By Paul Lin Time and Date Functions (continue) Example 7-4 measuring program execution time (accuracy – 1/100 th of a second) using cputime function Example 7-4 measuring program execution time (accuracy – 1/100 th of a second) using cputime function t1_1 = cputime; for i =1:1000 num_array = inv(rand(30)); num_array = inv(rand(30));end t1_2 = cputime; time_1000 = t1_2 - t1_1 time_once = time_1000/1000 time_1000 = time_once = e e-004

February 7, 2005 Lecture 7 - By Paul Lin Time and Date Functions Example 7-5 measuring program execution time (accuracy – 1/100 th of a second) using tic and toc functions Example 7-5 measuring program execution time (accuracy – 1/100 th of a second) using tic and toc functions tic; for i =1:1000 num_array = inv(rand(30)); end toc elapsed_time =

February 7, 2005 Lecture 7 - By Paul Lin Special Variables and Constants Example 7-6: AC circuit calculation using complex numbers. A RLC circuit is shown on this slide, find a) Total impedance Z b) Voltage and current across each components

February 7, 2005 Lecture 7 - By Paul Lin Special Variables and Constants (continue) Example 7-6: Analysis: Domain knowledge XL = 2πfL, where L is the inductance in Henry, f is the frequency of ac source XL = 2πfL, where L is the inductance in Henry, f is the frequency of ac source XC = 1/(2 πfC), where C is the capacitance in Farard XC = 1/(2 πfC), where C is the capacitance in Farard Z = R + j(XL – XC) -- total impedance, where j shows the imaginary component of a complex number Z = R + j(XL – XC) -- total impedance, where j shows the imaginary component of a complex number I = E/Z, total current I = E/Z, total current VR = I*R, voltage drop across resistor VR = I*R, voltage drop across resistor VL = I*XL, voltage drop across the inductor VL = I*XL, voltage drop across the inductor VC = I*XC voltage drop across the capacitor VC = I*XC voltage drop across the capacitor

February 7, 2005 Lecture 7 - By Paul Lin Special Variables and Constants (continue) Example 7-6: MATLAB Program %RLC_1.m f = 60; R = 8; % Peak value of the sine wave e = 10; XL = j*6; XC = -j*2; Z = R + (XL+XC) theta = angle(Z) % pi % 180 pi % = ---- % theta_degree theta theta_degree = (180*theta)/pi % degree = pi mag_Z = abs(Z)

February 7, 2005 Lecture 7 - By Paul Lin Special Variables and Constants (continue) Example 7-6: MATLAB Program (cont.) %RLC_1.m% I = e/Z I_thea_degree = angle(I) * (180)/pi I_mag = abs(I) VR = I*R VL = I*XL VC = I*XC VR + (VL + VC)% e = 10 volt VR = i i VL = i i VC = i i >> VR + (VL + VC) ans = 10 10

February 7, 2005 Lecture 7 - By Paul Lin 18 Summary Managing Variables and Workspace Managing Variables and Workspace MATLAB Commands for Working with Files and the Operating System MATLAB Commands for Working with Files and the Operating System Controlling Command Windows Controlling Command Windows Date and Time Functions Date and Time Functions Special Variables and Constants Special Variables and Constants

February 7, 2005 Lecture 7 - By Paul Lin 19 Question? Answers