Iterative solution to approach desired value

1 次查看(过去 30 天)
Hello,
I would like to find desired value Q = 7.76 using starting external solver in my Matlab script. Input for the external solver is value p. From several runs of the external solver I found the following values of p = pQ(:,1) and corresponding Q = pQ(:,2). How to find desired value 7.76? I found several examples of algorithms like Newton-Raphson but they use analytical equation, what I don't have here. Could you help to write such script?
Best regards
Michal
pQ = [
0.99471e+5 20.014;
0.99871e+5 4.89;
99795.887596 7.735;
99795.941823 7.733;
99795.964903 7.732;
99795.976825 7.731;
99796.01 7.73
]

采纳的回答

Walter Roberson
Walter Roberson 2022-5-19
编辑:Walter Roberson 2022-5-19
fzero() or fsolve().
If you need to be able to look at the complete source code then https://www.mathworks.com/matlabcentral/fileexchange/72478-bisection-method
Note that when you do not reply to my suggestions such as https://www.mathworks.com/matlabcentral/answers/1721605-iterative-solution-to-achieve-convergence#comment_2165925 then it is difficult for the volunteers to guess what you need different than what has already been suggested.
  8 个评论
Torsten
Torsten 2022-5-19
编辑:Torsten 2022-5-19
I restricted the search interval to (90000:100000):
p0 = 99.925e+3 ; % some start value for p in [90000:100000] such that f(p) = 7.76
p0_trans = tan( (p0-95000)/5000 * pi/2);
p = fzero(@fun,p0_trans);
p_backtrans = 2/pi*atan(p)*5000 + 95000
function res = fun(p)
p_backtrans = 2/pi*atan(p)*5000 + 95000;
% Calculate Q as a function of p
save('p_value.mat',num2str(p_backtrans))
run external_solver
results = readtable('Results.txt')
Q = results.Q
res = Q - 7.76;
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by