필터 지우기
필터 지우기

Iterative solution to approach desired value

조회 수: 3 (최근 30일)
M Teaxdriv
M Teaxdriv 2022년 5월 19일
댓글: M Teaxdriv 2022년 5월 20일
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
M Teaxdriv
M Teaxdriv 2022년 5월 20일
Thanks a lot for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (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