Need help to put condition in my optimization function

Here is my code:
function T0=tw0Solve(t1,s1,s2,rho,P)
T0= fsolve(@(tw0) (exp(-s2.^2./2).*exp(tw0.*s2).*(1-qfunc((t1-s1-rho.*tw0+rho.*s2)./sqrt(1-rho.^2)))./(1-qfunc((t1-rho.*tw0)./sqrt(1-rho.^2))))-P,rand);
end
Where for a given t1 we are trying to find tw0 that minimizes the function T0. But for some initial value the qfunc((t1-s1-rho.*tw0+rho.*s2)./sqrt(1-rho.^2)) becomes =1 which starts to provide error in fsolve as i start to get 0/0 form. How can I put a condition in this that helps me do something like this while it searches for tw0 and encounters a 0/0 form .
if qfunc(t1,tw0) < -3
T0=()
else
T0=()
end

 채택된 답변

Torsten
Torsten 2019년 8월 19일

0 개 추천

T0= fsolve(@(tw0) (exp(-s2.^2./2).*exp(tw0.*s2).*(1-qfunc((t1-s1-rho.*tw0+rho.*s2)./sqrt(1-rho.^2))))-P*(1-qfunc((t1-rho.*tw0)./sqrt(1-rho.^2))),rand);

댓글 수: 6

Hello , the ratio is (1-q())./(1-q())-P
But what u are suggesting is (1-q())-p*(1-q()) which changes my original equation
I multiplied the equation by the denominator of the first expression which doesn't change the solution.
Yes, I didnt see that, Thanks for helping but u know any different way to do it?
Why ? Doesn't it solve your problem ?
No, it still gives errors for some initial value of two when the initial conditions(s1,s2,rho) changes. Is there a way to put restrictions on two while fsolve function searches for two?
Plotting the function which produces problems in the relevant range for "two" might help to get a reasonable initial guess and to identify the cause of errors:
two = linspace(a,b,n);
ftwo = (exp(-s2.^2./2).*exp(tw0.*s2).*(1-qfunc((t1-s1-rho.*tw0+rho.*s2)./sqrt(1-rho.^2))))-P*(1-qfunc((t1-rho.*tw0)./sqrt(1-rho.^2)));
plot (two,ftwo)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2019년 8월 16일

댓글:

2019년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by