Need help to put condition in my optimization function
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Torsten
2019-8-19
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 个评论
Torsten
2019-8-26
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Direct Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!