User Tools

Site Tools


gibson:teaching:spring-2018:math445:lab8

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

====== Math 445 lab 9: 3d graphics ====== Important matlab commands: <code> linspace meshgrid pcolor surf surfc contour contourf quiver plot3 colorbar load subplot shading </code> ===== Problem 1: pcolor, meshgrid, shading, subplot ===== Skim the Matlab documentation for ''linspace, meshgrid,'' and ''pcolor''. Create a 2D mesh from −π to π with 30 points in both the //x// and //y// directions. Then for each position in the mesh let //z = cos(x) sin(y)//. Use ''pcolor,'' ''axis equal,'' and ''axis tight'' to generate this figure: {{:gibson:teaching:fall-2012:math445:a.png?nolink&500|}} But don't you hate those ugly black lines? You can get rid of them with the ''shading'' command. Use ''subplot'' and the ''shading'' command to generate this figure: {{:gibson:teaching:fall-2012:math445:lab10-fig2.png?nolink&500|}} ===== Problem 2: surf ===== Create a 2D mesh from −π to π with 20 points in both the ''x'' and ''y'' directions, let ''z = cos(x) sin(y)'' pointwise, and then recreate this figure using the ''surf'' and ''colorbar'' commands. {{:gibson:teaching:fall-2012:math445:lab10-fig3.png?400|}} ===== Problem 3: surf in the shade ===== Create a 2D mesh from −10 to 10 with 100 points in both the ''x'' and ''y'' directions, let $r = \sqrt{x^2 + y^2}$ and ''%%z = 5 sin(r)/r%%''. Then recreate Figure 4 using the ''surf'' and ''shading'' commands. {{:gibson:teaching:fall-2012:math445:lab10-fig4.png?500|}} ===== Problem 4: surf 'n' subplot ===== Create a 2D mesh from −π to π with 100 points in both the x and y directions and then recreate Figure 5, using the functions ''z = cos(x/2) cos(y/2)'', ''z = sin(x) cos(y/2),'' ''z = cos(x/2) sin(y)'', and ''z = sin(x) sin(y)''. {{:gibson:teaching:fall-2012:math445:lab10-fig5.png?500|}} ===== Problem 5: mystery plot ===== Enter the following code into a script file, save the figure produced as a '.jpg' or '.png' image, and include it with your project. What does the image produce? What is the role of the 'C' variable? <code> [phi,theta] = meshgrid(linspace(0,2*pi,100)); X=(cos(phi) + 3) .* cos(theta); Y=(cos(phi) + 3) .* sin(theta); Z=sin(phi); C=sin(3*theta); surf(X,Y,Z,C) shading interp </code> ===== Problem 6: quiver plot ===== The function \begin{eqnarray*} f(x,y) = 2 e^{-(x-1)^2 - (y-1)^2} + e^{-(x+1)^2 - y^2} \end{eqnarray*} is a rough scale model of a pair of small mountains named Monte Sol and Monte Luna on the outskirts of Santa Fe, New Mexico. Monte Sol, the bigger of the two mountains is about 200 meters high above the plain, so the scale is 1 = 100 meters. {{:gibson:teaching:spring-2015:math445:montesol.png?direct&400|}} **(a)** Reproduce the above surface plot in Matlab. **(b)** In a gentle rainstorm, water will flow down the mountains in the direction of steepest descent, i.e. along the negative of the gradient of $f$. Find the gradient of $f$ using elementary calculus, then make an $x,y$ plot with both contours of the mountain height $f$ and a quiver plot showing the direction of flow of rainwater. ===== Problem 7: inviscid fluid flow within a square corner ===== The inviscid 2d fluid flow within a square corner with solid walls at $x=0$ and $y=0$ and the domain $x \geq 0$ and $y \geq 0$ has velocity components \begin{eqnarray*} v_x &= v_0 \, x \\ v_y &= -v_0 \, y \end{eqnarray*} Make a quiver plot of this flow for $0 \leq x \leq 1$ and $0 \leq y \leq 1$, and with $v_0 = 1$. Label the axes and title the plot. ===== Problem 8: inviscid fluid flow past a semicircular bump ===== The inviscid 2d fluid flow past a semicircular bump of radius $a$ centered at the origin on a flat wall at $y=0$ has velocity components \begin{eqnarray*} v_x &= v_0 \left(1 - a^2 \frac{x^2 - y^2}{(x^2+y^2)^2}\right) \\ v_y &= -2 a v_0 \frac{xy}{(x^2+y^2)^2} \end{eqnarray*} Make a quiver plot of this flow for $a=1$, $v_0=1$, $-3 \leq x \leq 3$ and $0 \leq y \leq 3$, excluding the interior of the bump, where $x^2 + y^2 < a^2$. Draw a blue curve that shows the surface of the semicircular bump. Make the $x$ and $y$ axis have the same scale, label the axes, and title the plot. ===== Bonus ===== Draw a Klein bottle in Matlab. Feel free to search the web, but understand whatever you use. Attribution: Parts of this lab are adapted from Prof.Mark Lyon's Math 445 Advanced Graphics lab, which is adapted from Octave demos at [[http://yapso.sourceforge.net/demo/demo.html]].

gibson/teaching/spring-2018/math445/lab8.1522693787.txt.gz · Last modified: 2018/04/02 11:29 by gibson