MCE 372 Engineering Analysis MATLAB Review MATLAB What
MCE 372 Engineering Analysis MATLAB Review
MATLAB – What Is It ? Where Is It? l l Name is from matrix laboratory Powerful tool for – – – Computation and visualization of engineering, science and mathematics Communication of ideas Programming: l l Built-in editor, debugger, and help Many predefined functions (grouped in toolboxes) Interpreted or compiled programs Located on all ECC PC’s & in many department facilities
How Do We Want To Use MATLAB In This Course? Write Simple MATLAB Programs to Do the Following: - Perform Particular Calculations - Display/Plot Results for Interpretation
Creating Your Own Program Script (m-file) Concept l M-file is a collection of MATLAB commands – – l l File format: Name. m Commands are executed one by one sequentially – – l Can be re-executed Is easily changed/modified, transferred or e-mailed File is executed by typing its name (without. m) Results appear in the command window (or use ; ) Can be created using any text editor, but is most easily developed in MATLAB Editor Window
Boot Up Default MATLAB Window Opens Editor Window to create new program Help menu provides answers to most questions In this window: - type & edit commands - test & run program - save work when finished
Demo MATLAB Code Calculate & Plot Equation: y=2 x+30 x 2 -2 x 3 Dot needed for elementby-element operation Semicolon used to suppress output to Command Window – commonly desired
Plotting Line Specifiers Change the Look Especially Handy When Plotting Several Lines on Same Graph Use Help Menu to Find Out More
Example Code % MCE 372 Demo Program % Make Multiple Plots on Same Axes with Legends clc; clear all; clf x=0: 0. 1: 10; y 1=2*x+30*x. ^2; y 2=10*x. ^3; y 3=200*x % Plot all functions on same axes plot(x, y 1, 'k', 'linewidth', 2) hold on; grid on plot(x, y 2, 'b', 'linewidth', 2) plot(x, y 3, 'r', 'linewidth', 2) xlabel('x'); ylabel('y') title('MCE 372 Demo Plot') legend('y 1', 'y 2', 'y 3')
- Slides: 8