MATLAB: How to write a code that works like MS Excel “Goal seak”

MATLABnonlinear

I'm working on a thermodynamic problem, and i have to find a pressure value that solves:
Value of η and are known, are function of that is the value i'm looking for.
in particular:
s9_1s = s8 ; %known
x9_1 = 0.98;
h9_1s = XSteam('h_ps',p9_1,s9_1s); % as you can see h values that are functions in wich p9_1 (that is the objective) is a parameter.
x9_1s = XSteam('x_ps',p9_1,s9_1s);
h9_1 = XSteam('h_px',p9_1,x9_1);
The problem is that i can't write in a explicit form, because of the function XSteam, so i'm not able to use Fsolve or similar.
Can anyone give me some help?

Best Answer

What about fzero? Your code could be structured like
p90 = ... % put initial guess here
p9_1 = fzero(@(p) fn(p, XSteam), p90);
function Z = fn(p9_1, XSteam)
s9_1s = s8 ; %known
x9_1 = 0.98;
eta = ...
h8 = ...
h9_1s = XSteam('h_ps',p9_1,s9_1s);
x9_1s = XSteam('x_ps',p9_1,s9_1s);
h9_1 = XSteam('h_px',p9_1,x9_1);
Z = (h8 - h9_1)/(h8 - h9_1s) - eta;
end
View doc fzero for details on exact syntax etc of fzero.