Lab 4: Numerical Methods And Visual Checks
Goal
Use MATLAB numerical methods responsibly by pairing every computed answer with a visual or residual check.
Setup
Work in a folder called week04. Start scripts from a clean workspace:
clear; clc; close all;Part A: Roots And Residuals
Open week04_root_integration_checks.m.
Run the script and answer:
- What equation is being solved?
- How many roots are found?
- What brackets are used?
- What is the residual at each root?
- What would be missing if the script only printed the first root?
Part B: Change The Equation
Modify the root-finding section for:
f = @(x) cos(x) - x;Use the interval [0, 2].
Record:
- the root;
- the residual;
- a plot showing the crossing;
- one sentence explaining why the answer is credible.
Part C: Integration By Function And By Data
The script compares integral with trapz.
Change the number of sampled points used by trapz:
x_data = linspace(0, 6, 7);
x_data = linspace(0, 6, 31);
x_data = linspace(0, 6, 201);Answer:
- How does the estimate change?
- Which estimate is closest to
integral? - Why does sample spacing matter?
Part D: ODE Solver Check
Open week04_ode_solver_check.m.
Run the script and answer:
- What differential equation is being solved?
- What are
tspanandy0? - What does the initial-condition check verify?
- What changes when output times are requested explicitly?
Part E: Surface And Contour
Open week04_surface_contour_visualization.m.
Run the script and answer:
- What function of two variables is being plotted?
- What does
meshgridcreate? - What does the surface plot show well?
- What does the contour plot show more clearly?
Part F: Modify The Surface
Change the plotted function to:
Z = X .* exp(-X.^2 - Y.^2);Then:
- Update the title.
- Find the approximate maximum value.
- Record the approximate
(x, y)location of that maximum.
Deliverable
Submit a short note containing:
- one root-finding result with residual;
- one integration comparison;
- one ODE solve with an initial-condition check;
- one surface or contour plot;
- one paragraph explaining how the checks changed your confidence.
AI Use
If you ask an LLM for help, include:
- the prompt;
- the generated code or explanation;
- the check you used before trusting it;
- one thing the LLM did not verify.