Pass a dependency through a helper

The function file motorInput.m contains a main function and a local helper function:


MATLAB
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:


MATLAB
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?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More User Defined Functions and Function Files Questions: