HW 4 (Ch. 5: Plotting)
Problem 1 – Where Do the Two Speed Curves Cross?
Two speed functions are given: u = 2·log₁₀(60x+1) and v = 3·cos(6x), both in mph, over 0 ≤ x ≤ 2 miles.
•
Plot u and v versus x on the same axes using a fine discretization (at least 1000 points), with
distinct line styles/colors, full labels (xlabel, ylabel, title), grid on, and a legend
identifying each curve.
•
These are transcendental functions, so u = v cannot be solved for exactly by hand. Instead,
work directly from your discretized vectors: compute d = u − v, then use sign changes in d to
find every index where the two curves cross within the domain (explore diff, find and
sign with the help/doc browser).
•
For each crossing you find, report the approximate x location (miles) and the corresponding
speed (mph), and mark each crossing on your plot with a distinct marker (e.g., a black circle)
so it stands out.
In a comment, explain why increasing the number of points in your x vector makes your crossing estimate
more accurate, and what fundamentally limits how precise this sign-change method can ever be, no matter
how many points you use.
Problem 2 – Lift and Drag on an Airfoil
Lift and drag on an airfoil are predicted by L = ½·ρ·C_L·S·V² and D = ½·ρ·C_D·S·V², where both C_L and C_D
depend on angle of attack α via:
•
C_L = 4.47×10⁻⁵·α³ + 1.15×10⁻³·α² + 6.66×10⁻²·α + 1.02×10⁻¹
•
C_D = 5.75×10⁻⁶·α³ + 5.09×10⁻⁴·α² + 1.8×10⁻⁴·α + 1.25×10⁻²
Plot lift and drag versus V for 0 ≤ V ≤ 150 mph (convert to ft/sec first). Use ρ = 0.002378 slug/ft³, α = 10°,
S = 36 ft². Results for L and D should be in pounds.
Problem 3 – Comparing Axis Scales
Consider y(x) = sqrt[ (100·(1−0.01x²)² + 0.02x²) / ((1−x²)² + 0.1x²) ]. Generate a 2×2 subplot of y(x) for 0
≤ x ≤ 100, using regular plot, semilogx, semilogy, and loglog (one per subplot). Use fine enough
discretization to make the plot smooth. Label all axes and titles, and turn the grid on. Which plot conveys
the most information?
Problem 4 – Plotting a Torus
Plot a torus in MATLAB with major radius R = 10 and tube radius r = 5. (Background on a torus:
en.wikipedia.org/wiki/Torus.) Hint: explore meshgrid and surf, colormap, colorbar.
Problem 5 – SNR Across Multiple Signal Levels
SNR is a measure used in science and engineering that compares the level of a desired signal to the level
of background noise, often expressed in decibels (dB):
SNR = 10*log10(P_signal / P_noise)
Noise power ranges from 10 to 2000 W in 5 W steps.
•
Compute and plot SNR versus noise power on a semilogx (log x-axis) for three different
reference signal power levels: 50 W, 100 W, and 200 W -all three curves on the same axes,
each with a distinct line style/color, and a legend identifying each signal level. (Hint: think
about how you could produce all three curves at once using array operations -the way you
combined vectors into 2-D grids of results back in Chapter 4 -rather than writing the
calculation out three separate times.)
•
For each of the three curves, use logical indexing -not a manual calculation -to find the noise
power at which that curve's SNR first drops below 0 dB, and mark that point on the plot with
a distinct marker.
In a comment, describe the trend: how does the noise power at which SNR crosses 0 dB change as the
reference signal power increases?
Problem 6 – Mapping the Potential Field of an Electric Dipole
Two point charges sit in the x–y plane: q₁ = +5 nC at (−2, 0) cm and q₂ = −5 nC at (+2, 0) cm -an electric
dipole. The electric potential at a distance r from a point charge q is V = k·q/r, with k = 8.99×10⁹ N·m²/C².
The total potential at any point is the sum of the contributions from both charges.
•
Build a meshgrid of X and Y covering − 6 cm to 6 cm in both directions (convert to meters
before using the potential formula), and compute the total potential V at every grid point.
•
Right at each charge's exact location, r = 0 and the formula blows up. Decide how you will
keep this from ruining your plot (for example, excluding grid points closer than some small
radius to each charge, or capping the color/contour range) and explain your choice in a
comment -more than one approach is reasonable, but you must justify the one you pick.
•
In a figure, produce a contour(X, Y, V) plot with a colorbar, fully labeled (axes in cm,
a title, and a colorbar label indicating volts).