1 / 31

Computer Application in Engineering Design

Computer Application in Engineering Design. Lecture No 02 Engr. Aamir Arsalan. Colon Notation. Example. Deleting Rows and Columns. Multiple commands on same line. Array Operation. Dot Operations. Example. Example. Linear Algebra, Vectors and Matrices. Few basic MATLAB Commands. rank

billyv
Download Presentation

Computer Application in Engineering Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Application in Engineering Design Lecture No 02 Engr. Aamir Arsalan

  2. Colon Notation

  3. Example

  4. Deleting Rows and Columns

  5. Multiple commands on same line

  6. Array Operation

  7. Dot Operations

  8. Example

  9. Example

  10. Linear Algebra, Vectors and Matrices • Few basic MATLAB Commands. • rank • det • inv • eig • diag Type “help matfun” (Matrix functions - numerical linear algebra) in the Command Window for more information, or type “help elmat” (Elementary matrices and matrix manipulation).

  11. Scripts and user defined functions • Scripts or m-files are text files containing MATLAB code. • Use the MATLAB Editor or another text editor to create a file containing the same statements you would type at the MATLAB command line. • Save the file under a name that ends with “.m”.

  12. MATLAB Editor

  13. MATLAB Script • A Script is a collection of MATLAB commands and functions that is bundled together in a m file. When you run the Script, all the commands are executed sequentially.

  14. MATLAB Script • In the Editor you create a sequence of MATLAB commands that you save as a m-file (the file extension ends with .m). Push the “Run” button when you want to run your program.

  15. MATLAB Script • If the code contains errors or warning the MATLAB compiler will let you know by displayingsome colors symbols to the right in the Editor • Running a m-file in the Command window (just type the name of the m-file and hit Enter to run the m-file)

  16. Activity • Create a Script (M-file) where you create a vector with random data and find the average and the standard deviation. Run the Script from the Command window.

  17. Functions • Operate on information (inputs) fed into them and return outputs • Have a separate workspace and internal variables that is only valid inside the function. • MATLAB includes more than 1000 built-in functions that you can use, but sometimes you need to create your own functions.

  18. Functions • To define your own function in MATLAB, use the following syntax: • how to declare a function with one input and one output • how to declare a function with multiple inputs and multiple outputs

  19. Example • Here is a simple example. • Note! The function name (add) and the name of the file (“add.m”) need to be identical.

  20. Example

  21. Activity • Create a function called “linsolution” which solve

  22. Activity • Create a function calc_averagethat finds the average of two numbers.

  23. Activity • Create a function circle that finds the area in a circle based on the input parameter

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

  25. Example

  26. 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:

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

  28. Hold Command • Another approach is to use the hold command.

  29. 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.

  30. Questions??

  31. Thank You!!! 

More Related