Does MATLAB calculate parameters unlisted in the result list of arguments?

73 views Asked by At

We know that MATLAB supports functions outputting multiple results in a matrix.

For example, [J, grad] = linearRegCostFunction(X, y, theta, lambda) returns [J, grad] if both parameters appear on the left-hand side like [P, Q]. But when grad is missing, calling P=linearRegCostFunction(X, y, theta, lambda) would still give me the J value for my variable P.

Now my question is, does MATLAB spend computational resources calculating grad but simply not return it, or does it actually "realize" that only one of the result parameters is needed and skips the calculation for all the unlisted parameters?

Thanks!

0

There are 0 answers