

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A homework assignment from eps 109, fall 2008, instructed by burkhard militzer. The assignment includes tasks on 2d plotting with six functions, loops and if statements in matlab, and 3d plotting of sound waves from two speakers. Students are required to create plots, label axes, add legends, and answer specific questions related to the tasks.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Student name: Bugs Bunny EPS 109, Fall 2008 Email to: Edwin Kite ([email protected]) Instructor: Burkhard Militzer
Due date: Monday Sept 8, 2008, midnight (1) 2D plotting: Make one 2D plot for 0 ≤x ≤1 containing the following 6 functions f(x) = x g(x) = r x (1-x) for r={0.5, 1.5, 2.5, 3.5, and 4}. Label the axes, choose very different line styles for each curve, and add a legend for each curve. Please insert the resulting graph here as PNG file. For what values of r do f(x) and g(x) intersect? Now make a second plot where you show f(x) and g(g(x)) for the given set of r values. Include the plot here as well. What is the highest number of points where both functions interest, f(x)=g(g(x))? For which r value does this happen? (2) Loops and if statements: Open the Matlab Help window and read the section MATLAB →Getting started →Programming →Flow Control. Pay special attention to loops and if statements. Write a loop that prints all odd number less than 20. Cut and paste code here: Modify the loop that it prints all those number expect 13. Cut and paste code here: Search for the function “mod” in the Matlab help window and learn about it. Then write a loop that prints all odd numbers less than 100 that are not divisible by 7. Cut and paste code here: (3) Things that are not perfect: Look at the code below and try to predict what it will print a= for i=1: a=2a b=(2a+1) – (2*a) end Explain the different values that are printed for ”b”. (continued on next page)
(4) 3D plotting: The example discussed the lab handout [X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; mesh(X,Y,Z,'EdgeColor','black') surf(X,Y,Z) colormap hsv colorbar shows the decay of a sound wave that is emitted from a loud speaker at (x,y)=(0,0). “R” is a matrix containing all distances. Read about the operators “.^” and “./” in MATLAB →Getting started →Matrices and Arrays. Now study the case of two load speakers, one at (-x 0 ,0) and one at (+x 0 ,0) with x 0 =2. Add the resulting amplitudes Z 1 and Z 2. You should obtain an interference pattern. Adjust your grid spacing and range of plotting so that the interference effect can be easily identified. Insert your most appealing plot as PNG file here. (5) Optional (not included in grade): Floating-point arithmetic is not exact, which can to lead surprising results. Try for i=1:1/7: if (exp(log(i))==i) fprintf('i = %f\n',i); else fprintf('i = %f strange\n',i); end end How many times should the code print the word “strange”? Should it print it at all? Why does it do that? The problem is the “==” operator. How should one write a code that performs the comparison safely? Introduce a small number ε.