{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Example 1 plot y1 sinx and y2 cosx with x in 0 2

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 = sin(x) and y2 = cos(x) with x in 0 2 ] on the same graph. Use a solid line for sin(x) and the symbol + for cos(x). The rst step is to de ne a set of values for x at which the functions will be de ned. x = 0 : 0.1 : 2*pi y1 = sin(x) y2 = cos(x) plot(x, y1, '-', x, y2, '+') the end of each line directs Matlab to not print the values of each vector. 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 Note: Ordinarily Matlab prints the results of each calculation right away. Placing at 1 2 Example 1 3 4 5 6 7 Another way to get multiple plots on the same graph is to use the hold command to keep the current graph, while adding new plots. Another hold command releases the previous one. For example, the following statements generate the same graph as in Example 1. Matlab remembers that the vector x is already de ned. 3 90 250 120 200 150 150 100 50 180 0 30 60 210 330 240 300 Example 2 plot(x, sin(x), '-') hold plot(x, cos(x), '+') 270 The next example shows how Matlab generates a spiral using the polar coordinate system. Example 2: Plot = 2 with 0 5 in polar coordinates. theta = 0: 0.2: 5*pi rho = theta.^2 polar(theta, rho, '*') The following example illustrates how to generate a mesh surface in Matlab . p Example 3: Plot z = sin(r)=r with r = x2 + y2, ;8 x 8, ;8 y 8. The rst step in displaying a function of two variables, z = f (x y ), is to use the meshgrid function to generate X and Y matrices consisting of repeated rows and columns, respectively, over the domain of the function. The function can then be evaluated and graphed. x = -8: .5: 8 y=x X,Y] = meshgrid(x,y) R = sqrt(X.^2 + Y.^2) + eps Z = sin(R)./R mesh(x, y, Z) % add eps to prevent R=0 % or mesh(X,Y,Z) Anything following % on a line is treated as a comment. We added eps (the machine ) to R to pre...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern