JSFiddle - React, Tailwind, and code Playground
by k6e2n0t12
JavaScript
var bisection = function(v0,theta,length,ys,ye){//predict bisection
return (v0*Math.cos(theta)*(1*v0*Math.sin(theta)+Math.sqrt( v0*Math.sin(theta)*v0*Math.sin(theta) - 2*9.8*(ye-ys) ))-length*9.8);
}
var a = 0;
var b = 100;
var e = 0.0001;
var ys = 1.1;
var ye = 0;
var length = 35.78;
var theta = 82.5/180*Math.PI;
while(1){
var m = (a+b)/2;
console.log(m,theta,length,ys,ye);
var fm = bisection(m,theta,length,ys,ye);
var fa = bisection(a,theta,length,ys,ye);
if(fm*fa<0)
b = m;
else
a = m;
if((b-a)/2<e){
v0 = a;
break;
}
}
console.log(v0);