08-04-08.mw

> xphug:= [ diff(theta(t),t) = piecewise(y(t)>0,( v(t)^2 - cos(theta(t))) / v(t),0),
        diff(v(t),t)     = piecewise(y(t)>0,-sin(theta(t)) - R*v(t)^2 ,0),
        diff(x(t),t)     = piecewise(y(t)>0, v(t)*cos(theta(t)), 0),
        diff(y(t),t)     = piecewise(y(t)>0, v(t)*sin(theta(t)), 0),
        diff(blackbox(t),t) = piecewise(y(t)>0, 1, 0)]:
with(DETools):with(plots):
 

> R:=0.3;
 

.3 (1)
 

> crash:=dsolve({op(xphug), theta(0)=-Pi/5, v(0)=2, x(0)=0, y(0)=1, blackbox(0)=0},
               numeric,  range=0..10, output=listprocedure):
 

> crash(10);
 

[t(10) = 10., (blackbox(t))(10) = 5.21589191691218712, (theta(t))(10) = -.203962215418803355, (v(t))(10) = 1.05464661853757002, (x(t))(10) = 4.98458992116906607, (y(t))(10) = -0.480033813404428634e-5]
[t(10) = 10., (blackbox(t))(10) = 5.21589191691218712, (theta(t))(10) = -.203962215418803355, (v(t))(10) = 1.05464661853757002, (x(t))(10) = 4.98458992116906607, (y(t))(10) = -0.480033813404428634e-5]
(2)
 

> crash(5.21589191691218712);
 

[t(5.21589191691218712) = 5.21589191691219, (blackbox(t))(5.21589191691218712) = 5.21588966729907888, (theta(t))(5.21589191691218712) = -.203962499208465986, (v(t))(5.21589191691218712) = 1.0546469135...
[t(5.21589191691218712) = 5.21589191691219, (blackbox(t))(5.21589191691218712) = 5.21588966729907888, (theta(t))(5.21589191691218712) = -.203962499208465986, (v(t))(5.21589191691218712) = 1.0546469135...
[t(5.21589191691218712) = 5.21589191691219, (blackbox(t))(5.21589191691218712) = 5.21588966729907888, (theta(t))(5.21589191691218712) = -.203962499208465986, (v(t))(5.21589191691218712) = 1.0546469135...
[t(5.21589191691218712) = 5.21589191691219, (blackbox(t))(5.21589191691218712) = 5.21588966729907888, (theta(t))(5.21589191691218712) = -.203962499208465986, (v(t))(5.21589191691218712) = 1.0546469135...
(3)
 

> crash(5.2);
 

[t(5.2) = 5.2, (blackbox(t))(5.2) = 5.20000000000000108, (theta(t))(5.2) = -.206000605718118623, (v(t))(5.2) = 1.05672526804671540, (x(t))(5.2) = 4.96816424611580754, (y(t))(5.2) = 0.34100291525404296...
[t(5.2) = 5.2, (blackbox(t))(5.2) = 5.20000000000000108, (theta(t))(5.2) = -.206000605718118623, (v(t))(5.2) = 1.05672526804671540, (x(t))(5.2) = 4.96816424611580754, (y(t))(5.2) = 0.34100291525404296...
(4)
 

> f:= proc(Theta)
 local  crash;
 crash:=dsolve({op(xphug), theta(0)=Theta, v(0)=2, x(0)=0, y(0)=1, blackbox(0)=0},
               numeric,  range=0..10, output=listprocedure):
 return(rhs(crash(10)[5]));
end:  
 

>
 

> f(-Pi/5);
 

4.98458992116906607 (5)
 

> plot(f,-Pi/4..Pi/4);
 

Plot_2d
 

> bisector := proc( f, low, high, epsilon)
  local mid, lo, hi;
  lo := evalf(low);
  hi := evalf(high);
  if (f(lo)>0) then error("f not neg at lo=",lo, "f=",f(lo)); fi;
  if (f(hi)<0) then error("f not pos at hi=",hi, "f=",f(hi)); fi;
  mid := evalf((lo+hi)/2);
  while ( abs(f(mid))>epsilon) do
     if ( f(mid) > 0) then
        hi:= mid;
     else
        lo:= mid;
     fi;
     mid := (lo+hi)/2;
print( [lo, hi], mid, "f(mid)=", f(mid));
  od;
  return(mid);
end:
 

> f(-.61);
 

5.04766135434097407 (6)
 

> f(-.65);
 

4.91446302688485481 (7)
 

> f(.50);
 

4.82516339141283357 (8)
 

> f(.48);
 

5.05851516991119876 (9)
 

> bisector(t->f(t)-5, -.61, -.65, .00001);
 

Error, (in bisector) f not neg at lo=, -.61, f=, 0.47661354e-1
 

> bisector(t->f(t)-5, -.65, -.61, .00001);
 

 

 

 

 

 

 

 

 

 

 

 

 

[-.6300000000, -.61], -.6200000000,
[-.6300000000, -.6200000000], -.6250000000,
[-.6250000000, -.6200000000], -.6225000000,
[-.6250000000, -.6225000000], -.6237500000,
[-.6237500000, -.6225000000], -.6231250000,
[-.6237500000, -.6231250000], -.6234375000,
[-.6237500000, -.6234375000], -.6235937500,
[-.6237500000, -.6235937500], -.6236718750,
[-.6237500000, -.6236718750], -.6237109375,
[-.6237500000, -.6237109375], -.6237304688,
[-.6237500000, -.6237304688], -.6237402344,
[-.6237500000, -.6237402344], -.6237451172,
-.6237451172 (10)
 

> bisector(t->f(t)-5, .50, .48, .00001);
 

 

 

 

 

 

 

 

 

 

 

[.50, .4900000000], .4950000000,
[.50, .4950000000], .4975000000,
[.50, .4975000000], .4987500000,
[.4987500000, .4975000000], .4981250000,
[.4981250000, .4975000000], .4978125000,
[.4981250000, .4978125000], .4979687500,
[.4981250000, .4979687500], .4980468750,
[.4981250000, .4980468750], .4980859375,
[.4981250000, .4980859375], .4981054688,
[.4981054688, .4980859375], .4980957032,
.4980957032 (11)
 

>