The function file motorInput.m contains a main function and a local helper function:
function Pin = motorInput(Pout) Pin = applyEfficiency(Pout); end function Pin = applyEfficiency(Pout) Pin = Pout/eta; end
Here, Pout and Pin represent power in W, and eta is dimensionless efficiency. In the Command Window, an engineer executes:
eta = 0.80; Pin = motorInput(800);
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?
Add eta as an input to both function declarations. Supply it in both the Command Window call and the call to applyEfficiency.
Add eta as an input to applyEfficiency and supply it in the helper call. Keep the main function's declaration and external call unchanged.
Add eta as an input to motorInput and supply it in the Command Window call. Keep the helper's declaration and call unchanged.
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:
The caller executes:
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.
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: