MIT6_094IAP10_assn02

MIT6_094IAP10_assn02 - Jan 26 2010 Homework 2 6.094...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Jan. 26, 2010 Homework 2 6.094: Introduction to Matlab Homework 2 This homework is designed to give you practice with writing functions and visualizing data. This assignment will give you more freedom than Homework 1 to choose how you implement your functions. You will just be graded on whether your functions produce the correct output, but not necessarily on how efficiently they’re written. As before, the names of helpful functions are provided in bold where needed. Homework must be submitted before the start of the next class. What to turn in: Copy the text from your scripts and paste it into a document. If a question asks you to plot or display something to the screen, also include the plot and screen output your code generates. Submit either a *.doc or *.pdf file. Keep all your code in scripts. If a specific name is not mentioned in the problem statement, you can choose your own script names. 1. Semilog plot . Over the past 5 years, the number of students in 6.094 has been 15, 25, 55, 115, 144. Class size seems like it’s growing exponentially. To verify this, plot these values on a plot with a log y scale and label it ( semilogy , xlabel , ylabel , title ). Use magenta square symbols of marker size 10 and line width 4, and no line connecting them. You may have to change the x limits to see all 5 symbols ( xlim ). If the relationship really is exponential, it will look linear on a log plot. 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3. Bar graph . Make a vector of 5 random values and plot them on a bar graph using red bars, something like the figure below. 1 2 3 4 5 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Bar Graph of 5 Random Values 2 Problem 2 removed due to copyright restrictions.
Image of page 2
Jan. 26, 2010 Homework 2 6.094: Introduction to Matlab 4 . Interpolation and surface plots . Write a script called randomSurface.m to do the following a. To make a random surface, make Z0 a 5x5 matrix of random values on the range [0,1] ( rand ). b. Make an X0 and Y0 using meshgrid and the vector 1:5 (use the same vector for both inputs into meshgrid). Now, X0, Y0, and Z0 define 25 points on a surface. c. We are going to interpolate intermediate values to make the surface seem smooth. Make X1 and Y1 using meshgrid and the vector 1:.1:5 (again use the same vector for both inputs into meshgrid). d. Make Z1 by interpolating X0, Y0, and Z0 at the positions in X1 and Y1 using cubic interpolation ( interp2 , specify cubic as the interpolation method). e. Plot a surface plot of Z1. Set the colormap to hsv and the shading property to interp ( surf , colormap , shading ). f. Hold on to the axes and plot the 15-line contour on the same axes ( contour ). g. Add a colorbar ( colorbar ). h. Set the color axis to be from 0 to 1 ( caxis ). The final figure should look something like this (if the figure isn’t copy/pasting into your document appropriately, try changing the figure copy options to use a bitmap): 5 . Fun with find . Write a function to return the index of the value that is nearest to a desired value. The function declaration should be: ind=findNearest(x, desiredVal) . x is a vector or matrix of values, and desiredVal is the scalar value you want to find. Do not assume that desiredVal
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the 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