how to find input value of a function knowing one of the outputs?

3 views (last 30 days)
Hello everyone!
i've got a matlab function defined as
[Q_hw,GUE,COP]=getGUE(T_hwi,T_set,T_ext,Q_gas)
What i need to do now is to find the correct Q_gas so that Q_hw is equal to a set value (let's say equale to 5). I assume to know T_hwi,T_set,T_ext and the set value of the output Q_hw but i have no info about GUE,COP.
Can anyone help me?
Thank you!
FP

Accepted Answer

dpb
dpb on 4 Mar 2019
Q_Htgt=5; % the target solution value
fnQ=@(QG) getGUE(T_hwi,T_set,T_ext,QG)-Q_Htgt; % define solver function
Q_guess = YourStartGuessValue; % need a starting value in neighborhood
Q=fzer0(@fnQ,Q_guess); % see if can find a zero
[~,GUE_tgt,COP_tgt]=getGUE(T_hwi,T_set,T_ext,Q); % solve for other values given the zero
NB: The values of the other arguments to getGUE and the target Q_H values are embedded in the anonymous function definition for fnQ; if you need to solve for another set of parameters or target value, those values must be redefined and then the definition of the anonymous function re-executed to make it reflect the changes.
See doc fzero for more details, examples with alternate ways to handle extra parameters.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!