简体   繁体   中英

Relate outputs of parent function to input of nested function

I am going to try and explain myself simply in the hopes of getting a simple answer.

Let's say I have a function 'calculate' that takes the inputs [t,k,r,x] and outputs [A,B,C,D] as follows:

function [A,B,C,D] = calculate(t,k,r,x)

Now lets say I have another function that takes these outputs as the inputs, and spits out more, different outputs, eg.

function [M,N] = again(A,B,C,D)

How do I link [M,N] to say k and t ? The overall aim is to minimise both M and N by optimising k and t , and I can guess that it has something to do with nested functions and passing parameters but I'm not sure how to start, and the start is all I want. Thanks

Take a look at the Matlab optimization toolbox . It provides functions for a multitude of optimization problems. Although I believe these functions only take one function as a parameter. Therefore for your case it would probably be best, if you do it like this if you can:

  1. Write function calculate.m with parameters (t,k,r,x) and save it.
  2. Write function again.m with parameters(t,k,r,x) and save it.
  3. Function again calls function calculate with parameters (t,k,r,x) and then continues to determine (M,N) from the output of calculate .
  4. in the Matlab toolbox optimization function, eg: fmincon(fun,x0,A,b), you then have to use again.m as the function you want to optimize (fun).

Hope that's good enough for a start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM