Plotting functions

Add to Favourites
Post to:

MORE MATLAB INSTRUCTIONS 1. Plotting functions In this section, the basics of plotting functions in MATLAB are described. Throughout we work with the example of two functions, f(t)=(2t + 1)e−t sin(t), and g(t)=(t − 1)e−t cos(t). Step 1, Specify the domain: Functions are defined on an interval called the domain. To plot the function in MATLAB, you need to specify the domain. Every domain has a left endpoint, a, and a right endpoint, b. Of course MATLAB does not plot the value of the function at every point between the a and b, only finitely many points with a regular spacing h. The syntax to specify the domain is, >>t = a : h : b For example, to plot our function on the interval[−1,1] with step size 0.05, the syntax is, >> t = 110.05:1 One word about this. Technically x is a data type called an array: just the ordered list of the numbers a, a+h,a+2h,. . . . The syntax for arithmetic with an array in MATLAB is different than the syntax for arithmetic with a number. Step 2, Specify the function: Here is a list of common operations used to define functions, and the corresponding syntax in MATLAB. In the list, y(t) and z(t) are names for functions or pieces of functions that are already specified. Operation y(t)+ z(t) y(t)z(t) y(t)n y(t)/z(t) sin(y(t)) cos(y(t)) ey(t) ln(y(t)) log10(y(t)) MATLAB Syntax y + z y.* z y.^n y./z sin(y) cos(y) exp(y) log(y) log10(y) For example, if the range t has already been defined, the function (2t + 1)e−t sin(t)is specified by, >>y =(2 .* t + 1 ).* exp( 11.t ).* sin(t ) Similarly, the function (t − 1)e−t cos(t) is specified by, >>z =(t 1  ). exp( 11.t ).* cos(t ) Step 3, Plot the function: The syntax to produce a 2Dplot whose domain is t annd whose function is y is >> h = plot(t,y) Note, you do not need to say “h =”, but this can be useful if you want to manipulate the plot later. MATLAB will produce the plot in a new window. Step 4, Plotting a parametrized curve; Several plots at once: MATLAB can plot a parametrized figure. For instance, for the parametrized curve (y,z)where y(t)=(2t + 1)e−t sin(t), z(t)=(t − 1)e−t cos(t), the syntax is, 1 >> i = plot(y,z) where y and z are specified as above. Note that when plotting parametrized curves, it is still necessaryto specify the tdommain But t doesn’t explicitly appear in the syntax of the plot. Also, MATLAB can plot several graphs (or parametrized curves) simultaneously. For simplicity, think of a graph as a parametrized curve (t,y(t)). For a number of parametrized curves, say (y1(t),z1(t)), (y2(t),z2(t)), the syntax to plot both of these curves in a single figure is, >> j = plot(y1,z1,y2,z2) Any number of curves can be plotted in a single figure: just write plot(y1,z1,...,yn,zn), where the functions y1,...,yn and z1,...,zn have already been specified. To simultaneously graph the functions yand z above over the interval t, the syntax is, >> k = plot(t,y,t,z) Step 5, Print or export your plot: To either print your plot or to export it as a JPEG file, click on the “File” button of the new window and then click on “Print” or “Export” in the popup mmenu There are other extras that you can find out by experimenting (such as adding labels to your axes). 2

Description
Functions are defined on an interval called the domain. To plot the function in MATLAB, the domain is to be  specified. The  left endpoint and the right endpoint the domain are explained here. List of common operations used to define functions, and the corresponding syntax in MATLAB is introduced.Plotting a parametrized curve is also discussed. it is necessary to specify the  t-­domain to plot a parametrized curve.
Instructor: Instructor: Prof. Jason Starr, Maths, 18.034: Honors Differential Equations, Spring 2004: 4. Some Instructions on Plotting Functions in MATLAB: Picard Iterates: Uniqueness: Massachusetts Institute of Technology: MIT Open Course Ware),http://ocw.mit.edu (Accessed 4February, 2012). License: Creative Commons BY-NC-SA: http://ocw.mit.edu/terms/#cc

Comments

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
LearnOnline Through OCW
OpenCourseWare
User
102 Followers

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect