Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matlab Workshop 1/10/07 Lesson 1: Matlab as a graphing calculator.

Similar presentations


Presentation on theme: "Matlab Workshop 1/10/07 Lesson 1: Matlab as a graphing calculator."— Presentation transcript:

1 Matlab Workshop 1/10/07 Lesson 1: Matlab as a graphing calculator

2 Lesson 1 focuses on basic use of Matlab as a graphing calculator. In this lesson you will: Use Matlab as a simple calculator Understand the main views in the Matlab application: (Command Window, Workspace, Command History, Array Editor, Editor) Write simple scripts using the editor Use Cell Mode to run and debug scripts Publish and document the results

3 Overview

4 Example 1.1: Defining a variable in Matlab.

5 Things to explain: Where is the command window? How do you interpret what is in the workspace? What happens if you leave out the semicolon? What do variables represent? Do spaces matter? Is Matlab case sensitive (i.e., is x different from X )? Do line breaks matter? How do I continue a command on the next line? Type the following in the command window: x = 3;

6 Example 1.2: Calculating a simple formula.

7 Find the value of the following polynomial at x = 3 : Things to explain: Why do I need to put * between 5.2 and x? Why is y underlined in red? Type the following in the command window: y = 4.1*x*x*x - 5.2*x - 2;

8 Example 1.3: Using functions and predefined constants in formulas.

9 Find the volume ( V ) of a cylinder with a radius ( r ) of 2.5 and a height ( h ) of 7.3. The formula for the volume of a cylinder is: Things to explain: Where did pi come from? Why not volume = pi*r*r*h? What is power? How do I find out what other built-in functions Matlab has? Type the following in the command window: r = 2.5; h = 7.3; V = pi*power(r,2)*h;

10 Example 1.3: Plotting the graph of a function

11 Graph the following function on the interval 0 to 5. Things to explain: How do I see what kind of values x and y hold? Is 1x100 different from 100x1? What are the actual values that x and y hold? How do I specify the spacing between the values in x? What happens if I leave the x out of the plot command? How can I make x into a vector when it used to just be an integer (Example 1.1). Type the following in the command window:

12 x = linspace(0, 5); y = 4.1*power(x, 3) - 5.2*x -2; plot(x, y);

13 Example 1.4: Writing a script and using cell mode.

14 Redo Examples 1.2 and 1.3 as a script file and debug in Cell Mode.

15 Exercises

16 Now try these exercises. Create a new script called Lesson1Exercises.m When you and your partner have completed the exercises, place your card in front of your computer. If you have questions raise your hand. 1. Graph the following on the interval [0, 5]:

17 Summary of syntax

18 Lines with comments start with % Line breaks matter. Use three dots (... ) to continue on the next line Matlab is case sensitive Variables can be reassigned to any type A variable designated as a x b double has a rows and b columns

19 Summary of strategies

20 Here are some summary strategies for working with Matlab: Develop Matlab code in small steps Use Cell Mode to debug each step Try simple numbers on each thing first Watch the types of the variables in the workspace as you work Don't move code to its own function until you've thoroughly debugged it in Cell Mode Document each small piece as you go Use the Matlab publish feature to document you're work. Keep the documentation updated or you will have no idea what you have after a few months


Download ppt "Matlab Workshop 1/10/07 Lesson 1: Matlab as a graphing calculator."

Similar presentations


Ads by Google