Skip to content
Advertisement

Finding root of a function with two outputs specified in return statement

I am currently writing a code in Python where the objective is to find the root of the output of a function with respect to input variable x. The code looks like this:

JavaScript

As can be seen in the code block above, there are two outputs specified:

  1. Equity_Solve
  2. Mezzanine_Solve

I now want to find the root for both outputs separately. If I comment out the Mezzanine_Solve part in the return statement, then the the optimize procedure gives me the solution I want. Obviously, I want to automate my code as much as possible. Is it possible to specify the output for which I want to find the root in the optimize statement?

I tried the following, without success:

JavaScript

Any help is appreciated. Thank you in advance!

Advertisement

Answer

I think the problem is that your function returns a tuple of numbers, but root is expecting a single number.

Assuming you want to solve each equation separately, then you could include an argument in Compound_Correlation_Function to switch between the functions:

JavaScript

Then pass the return_equity argument in as an extra argument via args, i.e. call

JavaScript

to solve Equity_Solve, and set args=(False,) to solve Mezzanine_Solve.

You could also define a function wrapper that calls Compound_Correlation_Function and returns only one of the values.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement