A heater transfers energy at a constant rate. The file heaterEnergy.m accepts scalar power P in W and duration t in minutes, and returns transferred energy E in kJ:
function E = heaterEnergy(P,t) t = t*60; E = P*t/1000; end
The caller executes:
t = 2.5; energy = heaterEnergy(650,t);
What value is stored in energy? Answer in kJ, to one decimal place.
Unlock full course notes by signing up
Discard or capture a returned load
A test technician saves this function as adjustedLoad.m in MATLAB's current folder. Both inputs and the returned load represent forces in newtons.
The technician then executes these commands in order in the Command Window:
Complete the table with the final values of afterDiscard and afterCapture. Enter exact integers in newtons. All inputs are ordinary numeric scalars.
Pass a dependency through a helper
The function file motorInput.m contains a main function and a local helper function:
Here, Pout and Pin represent power in W, and eta is dimensionless efficiency. In the Command Window, an engineer executes:
The call fails because eta is undefined inside applyEfficiency. There are no global variables or nested functions. Which revision supplies efficiency explicitly through the complete call chain?
Repair a two-output calculation
An engineer saves this code in resistorReport.m to calculate resistor power and energy:
Inputs are scalar current I in A, resistance R in ohms, and duration t in s. The intended outputs are power P in W followed by energy E in J. Assume constant current and resistance.
Compose functions to enforce a power limit
An engineer models a converter supplying a useful electrical load through a resistive cable. These two MATLAB function files are saved in the current folder.
File cableLoss.m:
File supplyPower.m: