University of Auckland · FACULTY OF ENGINEERING

ENGGEN 131 Chap.6 Function Handles, ODEs and Efficiency

- one subject, every graph, every model, every mark
5 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 6 of 10 · ENGGEN 131

Function Handles, ODEs and Efficiency

This chapter shows how function handles carry callable behaviour into root finders, minimisers and ordinary differential equation solvers. It matches solver signatures, reads adaptive output arrays, reasons from derivative sign and tests equilibrium behaviour. Efficiency claims are treated as evidence problems that require equivalent outputs, controlled workloads, repeated timing and scaling checks.

In this chapter

What this chapter covers

  • 01

    Named and anonymous function handles

  • 02

    Solver input signatures and output shapes

  • 03

    Derivative sign and qualitative trajectories

  • 04

    Adaptive time points and paired state arrays

  • 05

    Correctness checks before timing comparisons

Worked example · free

Reason about an approach to equilibrium

Q [3 marks]. For dy/dt=0.5(10-y) with y(0)=2, find the derivative at y=2 and y=8 and describe the direction. The weighting for “Reason about an approach to equilibrium” is an AskSia revision estimate, not a University mark allocation.
The flow sends a function handle into a solver, which selects evaluation points and returns matched arrays of independent variable and state.The flow sends a function handle into a solver, which selects evaluation points and returns matched arrays of independent variable and state.function handledescribes f(t,y)solver choosesevaluation pointstime and statearrays returned
The flow sends a function handle into a solver, which selects evaluation points and returns matched arrays of independent variable and state.
  • 1At y=2, the derivative is 4.
  • 1At y=8, the derivative is 1.
  • 1The state rises toward ten while the positive slope becomes smaller.
The derivatives are 4 and 1, so the trajectory increases and flattens toward ten.
Sia tip — Use the sign and changing magnitude of the derivative before trusting a plot.
Glossary

Key terms

Function handle
A MATLAB value referring to callable behaviour.
Equilibrium
A state where the derivative is zero and the model stops changing locally.
Preallocation
Reserving array storage before a loop fills its elements.
FAQ

Function Handles, ODEs and Efficiency FAQ

Why are solver time points uneven?

Adaptive solvers choose step sizes based on numerical needs, so interpret state values against the returned time array rather than an assumed fixed interval. Rehearse this distinction with a fresh model and solver-contract trace before relying on program output.

How do I check an ODE plot?

Evaluate derivative signs at the initial state, around any equilibrium and on both sides of a target to predict direction and flattening. Test the claim on a boundary case where the model and solver-contract assumptions become visible.

What makes an efficiency comparison fair?

Use the same input and workload, verify equivalent outputs, time the intended operation several times and examine behaviour as input size increases. Write the expected model and solver-contract state first, then compare it carefully with execution.

Study strategy

Exam move

Begin by writing the mathematical model independently of MATLAB. Name the independent variable, state variables, parameters, initial conditions and units. Check that both sides of every differential equation have compatible dimensions. Identify equilibrium states by setting the derivative to zero. Evaluate the derivative below, at and above each equilibrium so its sign predicts local movement.

This qualitative phase-line sketch becomes a solver-independent reference and can expose a reversed sign or misplaced parameter before numerical output is trusted. Translate the model into a function-handle contract. Record argument order, expected state shape and returned derivative shape. If arrays may be supplied, decide which operators must be elementwise.

Evaluate the handle manually at the initial state and another convenient state, then call it directly with those values before passing it to a solver. A concise anonymous function can still capture the wrong workspace parameter, swap state and time, or return a shape incompatible with the solver. Before reading a plot, inspect the first returned time and state to verify the initial condition.

Compare early movement with the initial derivative, locate whether the curve approaches or moves away from predicted equilibria and check whether flattening corresponds to a decreasing derivative magnitude. Use units and rough timescale to judge plausibility. A smooth curve demonstrates only that points were plotted; it does not establish that the intended model, sign, parameters or solver arguments were used.

When comparing numerical implementations, establish equivalence first. Choose identical inputs and a stated accuracy criterion, then calculate an exact equality result or a maximum discrepancy as appropriate. Keep solver tolerances or evaluation points comparable. Separate setup, file reading and plotting from the code region whose efficiency is being studied. Suppress display and perform a warm-up when relevant.

A faster result outside the permitted error tolerance is a different computation, not an optimisation. Gather timing evidence over repeated runs and several problem sizes. Report the median or another robust summary rather than selecting the fastest observation. Record the hardware-independent workload, including input size and number of evaluations, so the claim can be interpreted.

Look for scaling trends rather than overinterpreting a tiny difference at one size. Fixed overhead may dominate small problems, while allocation or repeated growth may dominate large ones. State uncertainty when timing differences are comparable to run-to-run variation. Finish revision by auditing one complete model: units, equilibrium, derivative signs, handle evaluation, initial condition, trajectory and numerical agreement.

Then design a fair timing comparison between two equivalent ways to compute one stage. Keep a log separating modelling defects, interface defects, numerical discrepancies and measurement flaws. In an exam response, present reasoning in that order. Mastery means predicting the qualitative answer before integration and supporting an efficiency claim with correctness, controlled workload, repetition and scaling evidence.

For synthesis, choose a one-state model with a known equilibrium and write its units, initial condition and expected direction on either side of equilibrium. Evaluate the function handle at three states, then inspect the first solver output and compare the curve with those sign predictions. Implement an equivalent direct calculation in two ways and define a numerical tolerance before timing either.

Measure the same workload repeatedly at several sizes, excluding plotting and setup, and report agreement plus median time. If the faster version misses the tolerance or uses fewer evaluations, reject the optimisation claim.

This workflow joins model validation, function-handle interfaces, qualitative ODE reasoning, numerical comparison and performance evidence, ensuring that a smooth plot or isolated timing cannot substitute for a correct and controlled argument.

A+Everything unlocked
Unlocks this Bible + all 34 of your University of Auckland subjects - and 1,000+ Bibles across every Australian university.
Sia - your ENGGEN131 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
ENGGEN131 · Introduction to Engineering Computation and Software Development - independent study guide on the AskSia Library. More University of Auckland subjects · Microeconomics across all universities