Computer Application in Engineering Design

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

Lecture 5.
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Matlab
2D Plots 1 ENGR 1181 MATLAB 12.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
1.3 ARRAYS, FILES, AND PLOTS + FOURIER SERIES BY MR. Q.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
General Computer Science for Engineers CISC 106 Lecture 09 James Atlas Computer and Information Sciences 9/25/2009.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Engineering Computation with MATLAB Second Edition by David M. Smith.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Structured Programming: Debugging and Practice by the end of this class you should be able to: debug a program using echo printing debug a program using.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
Introduction to Matlab
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
ME 123 Computer Applications I Lecture 16: More Matlab Programming: Secant Method, Review 4/4/03.
Introduction to Literate Programming in Matlab 2WN50 – Week programming-in-matlab.pptx?dl=0.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Tutorial on Matlab Basics
Matlab Programming for Engineers
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB
Loops BIS1523 – Lecture 10.
Introduction to Mat lab
Matlab Training Session 4: Control, Flow and Functions
Lecture 25.
L – Modeling and Simulating Social Systems with MATLAB
ECE 1304 Introduction to Electrical and Computer Engineering
CS1371 Introduction to Computing for Engineers
Two-Dimensional Plots
Matrices and Arrays.
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
MATLAB DENC 2533 ECADD LAB 9.
(Mohammed Sami) Ashhab
Matlab Workshop 9/22/2018.
Introduction To MATLAB
MATLAB Tutorial Dr. David W. Graham.
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
Plotting Multiple Graphs In The Same Plot
Types of Flow of Control
Structures- case, sequence, formula node
Loop Statements & Vectorizing Code
ANALYSIS OF CIRCUITS WITH ONE ENERGY STORING ELEMENT
Plotting Signals in MATLAB
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Loop Statements & Vectorizing Code
Presentation transcript:

Computer Application in Engineering Design Lecture No 03 Engr. Aamir Arsalan

Plotting Plotting is a very important and powerful feature in MATLAB.

Example

Activity In the Command window (or use the Script Editor) in MATLAB window input the time from t=0 seconds to t=10 seconds in increments of 0.1 seconds as follows: Then, compute the output y as follows: Use the Plot command:

Plotting Multiple Data Points in One Graph In MATLAB it is easy to plot multiple data set in one graph.

Hold Command Another approach is to use the hold command.

Activity Given the following differential equation: where , where T is the time constant. The solution for the differential equation is: Set T=5 and initial condition x(0)=1. Create a Script in MATLAB (.m file) where you plot the solution x(t) in the time interval 𝟎≤𝒕≤𝟐𝟓 Add Grid, and proper Title and Axis Labels to the plot.

Subplot Command The subplot command enables you to display multiple plots in the same window or print them on the same piece of paper. Syntax is:

Example

Plot Sin(x) and Cos(x) in 2 different subplots. Add Titles and Labels. Activity Plot Sin(x) and Cos(x) in 2 different subplots. Add Titles and Labels.

Customizing Plots There is lots of customizing you can do with plots, e.g., you can add a title, x- and y-axis labels, add a legend and customize line colors and line-styles. The functions for doing this is; title, xlabel, ylabel, legend, etc.

Line Styles For line colors and line-styles we have the following properties we can use for the plot function:

Marker Specifiers

Colors

Example

Flow Control and Loops You may use different loops in MATLAB • For loop • While loop If you want to control the flow in your program, you may want to use one of the following: • If-else statement • Switch and case statement

If-else Statement

If else Statements If A and B are scalars this works – but If A and B are matrices this might not work as expected! Use instead:

Operators

Logical Operators

Activity Create a function that finds the solution for x based on different input values for a, b and c.

Switch and Case Statements The switch statement executes groups of statements based on the value of a variable or expression. There must always be an end to match the switch. The general syntax is as follows:

Activity Create a function that finds either the Area or the circumference of a circle using a Switch Case statement

For Loop The For loop repeats a group of statements a fixed, predetermined number of times. A matching end delineates the statements. The general syntax is as follows:

Activity In mathematics, Fibonacci numbers are the numbers in the following sequence: 0, 1, 1, 2 ,3, 5, 8, 13, 21, 34, 55, 89, 144, … Write a function in MATLAB that calculates the N first Fibonacci numbers

While Loop The while loop repeats a group of statements an indefinite number of times under control of a logical condition. A matching end delineates the statements. The general syntax is as follows:

Activity Create a Script or Function that creates Fibonacci Numbers up to a given number.

Activity Extend your calc_average function from a previous task so it can calculate the average of a vector with random elements. Use a For loop to iterate through the values in the vector and find sum in each iteration: mysum = mysum + x(i); Test the function in the Command window.

Activity Create a function where you use the “if-else” statement to find elements larger than a specific value in the task above. If this is the case, discard these values from the calculated average. Example discarding numbers larger than 10 gives:

Questions??

Thank You!!! 