Mark Yourself Question
An engineer saves this code in resistorReport.m to calculate resistor power and energy:
function [P,E] = resistorReport(I,R,t) P = I^2*R; energy = P*t; end
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.
The caller executes:
[energy,power] = resistorReport(1.5,12,40);
Explain why the call fails, correct both the function body and the caller's output list, and calculate the values that should be stored in power and energy. Also state whether the successful call creates a variable named I in a caller workspace that previously had no I.
Unlock full course notes by signing up
Trace a local unit conversion
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:
What value is stored in energy? Answer in kJ, to one decimal place.
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?
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: