Three-way, a school sister asked me what is the three-point method, why should have a three-way

Source: Internet
Author: User

In monotone functions, we often use dichotomy to quickly search for feasible solutions. In the single-peak function, we use the three-way method to search for the extremum of the function. In general, the three-way method can be divided evenly, or the first point points at the midpoint of the left and right end points, the second point at the midpoint of the midpoint and the end.

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cmath>
using namespaceStd;
Double
H,V;
Double
F(DoubleA)
{

Double
G=9.8,Vx=V*Cos(A),Vy=V*Sin(A);
return
Vx*(Vy/G+sqrt((2*H*G+Vy*Vy)/(G*G)));
}

int
Main()
{

int
T;
scanf("%d",&T);
while
(T--)
{

scanf("%LF%LF",&H,&V);
Double
L=0,R=90.00;
while
((R-L) >=1e-10)
{

Double
ll,Rr;
ll=(L+R)/2;
Rr=(ll+R)/2;
If
(F(ll) <F(Rr))
L=ll;
else

R=Rr;
}
printf("%.2lf\n",F(L));
}

return
0;
}

Three-way, a school sister asked me what is the three-point method, why should have a three-way

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.