Problem Solving with MATLAB

Slides:



Advertisements
Similar presentations
Complex Numbers in Engineering (Chapter 5 of Rattan/Klingbeil text)
Advertisements

Impedance and Admittance. Objective of Lecture Demonstrate how to apply Thévenin and Norton transformations to simplify circuits that contain one or more.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
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 ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Resonant Circuit.
February 7, 2005 Lecture 7 - By Paul Lin 1 CPET 190 Lecture 7 Problem Solving with MATLAB Paul Lin
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
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.
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 Session 1 Simopekka Vänskä, THL 2010.
September 13, 2005 Lecture 4 - By P. Lin 1 CPET 190 Lecture 4 Problem Solving with MATLAB
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.
MATLAB Profiling Lien-Chi Lai, COLA Lab 2010/05/06.
ENG 1181 College of Engineering Engineering Education Innovation Center 1 Script File Input – Output : Chapter 4 PLEASE HAVE STUDENTS START MATLAB NOW.
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.
AC POWER & POWER FACTOR. Lesson Objectives  Compute and define apparent, reactive, and average power for capacitors, inductors, and resistors.  Compute.
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
Release Numbers MATLAB is updated regularly
BAHASA PEMROGRAMAN MATLAB as an Engineering Tool & Programming Language a lecture note for Civil Engineering students of PETRA Christian University Doddy.
Lesson 16: Series AC Circuits
Inductance, Electromagnetic Oscillations, and AC Circuits
AC Circuit Phasors Physics 102: Lecture 13
Introduction to Matlab
EGR 115 Introduction to Computing for Engineers
Lecture 6 (III): AC RESPONSE
Introduction to Programming for Mechanical Engineers (ME 319)
Principles & Applications
Introduction to MATLAB
MATLAB DENC 2533 ECADD LAB 9.
11/13/2018.
Lecture 08 AC POWER ANALYSIS
Alternating Current Circuits and Electromagnetic Waves
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
AC circuits Physics /23/2018 Lecture XIX.
PHYS 221 Recitation Kevin Ralphs Week 8.
Lecture 2 Introduction to MATLAB
ECE131 BASIC ELECTRICAL & ELECTRONICS ENGG
funCTIONs and Data Import/Export
Matlab.
Note on Indexing of Array Elements
Islamic University of Gaza
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
Complex Numbers in Engineering (Chapter 5 of Rattan/Klingbeil text)
C H A P T E R 13 A.C. Series Circuits.
Electrical Principles
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Electrical Principles
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Chapter 2 MATLAB Environment
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Problem Solving with MATLAB CPET 190 Lecture 7 Problem Solving with MATLAB Paul Lin http://www.etcs.ipfw.edu/~lin February 7, 2005 Lecture 7 - By Paul Lin

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

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

7-1 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 February 7, 2005 Lecture 7 - By Paul Lin

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

7-2 Working with Files and OS The commands for working with files and operating system Command Purpose pwd Show present working directory cd Change current working directory dir Directory listing (Window OS) ls Directory Listing (Unix/Linux OS) delete Delete file diary Save text of MATLAB session ! Execute OS commands February 7, 2005 Lecture 7 - By Paul Lin

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

7-3 Controlling the Command Window clc Clear command window home Send cursor home (upper-left corner of command window) format Set output format more Control paged output in command window echo Echo on/off commands inside script files, for debugging purposes February 7, 2005 Lecture 7 - By Paul Lin

7-4 Time and Date Functions Function Purpose date Calendar clock System clock; accuracy 1/100th of a second now Current date and time as serial date number datestr Convert a serial date number into the common date/time, save as a string cputime How many seconds the MATLAB session is active; accuracy 1/100 th of second etime Elapsed time function tic Start watch timer function toc Stop watch timer function February 7, 2005 Lecture 7 - By Paul Lin

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

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

7-4 Time and Date Functions (continue) 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)); end t1_2 = cputime; time_1000 = t1_2 - t1_1 time_once = time_1000/1000 time_1000 = 0.3610 time_once = 3.6100e-004 February 7, 2005 Lecture 7 - By Paul Lin

7-4 Time and Date 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 = 0.3610 February 7, 2005 Lecture 7 - By Paul Lin

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

7-5 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 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 I = E/Z, total current VR = I*R, voltage drop across resistor VL = I*XL, voltage drop across the inductor VC = I*XC voltage drop across the capacitor February 7, 2005 Lecture 7 - By Paul Lin

7-5 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) % 0.4636 pi % 180 pi % ----- = ---- % theta_degree theta theta_degree = (180*theta)/pi % 26.5615 degree = 0.4636 pi mag_Z = abs(Z) February 7, 2005 Lecture 7 - By Paul Lin

7-5 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 = 8.0000 - 4.0000i VL = 3.0000 + 6.0000i VC = -1.0000 - 2.0000i >> VR + (VL + VC) ans = 10 February 7, 2005 Lecture 7 - By Paul Lin

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

Question? Answers Email: lin@ipfw.edu February 7, 2005 Lecture 7 - By Paul Lin