08-04-01.mw

> R:=0.3:
xphug:= [ diff(theta(t),t) = ( v(t)^2 - cos(theta(t))) / v(t),
        diff(v(t),t)     = -sin(theta(t)) - R*v(t)^2 ,
        diff(x(t),t)     = v(t)*cos(theta(t)),
        diff(y(t),t)     = v(t)*sin(theta(t))];
 

[diff(theta(t), t) = `/`(`*`(`+`(`*`(`^`(v(t), 2)), `-`(cos(theta(t))))), `*`(v(t))), diff(v(t), t) = `+`(`-`(sin(theta(t))), `-`(`*`(.3, `*`(`^`(v(t), 2))))), diff(x(t), t) = `*`(v(t), `*`(cos(theta(...
[diff(theta(t), t) = `/`(`*`(`+`(`*`(`^`(v(t), 2)), `-`(cos(theta(t))))), `*`(v(t))), diff(v(t), t) = `+`(`-`(sin(theta(t))), `-`(`*`(.3, `*`(`^`(v(t), 2))))), diff(x(t), t) = `*`(v(t), `*`(cos(theta(...
(1)
 

> with(DETools):with(plots):
 

>
 

>
DEplot(xphug, [ theta(t), v(t), x(t), y(t) ], t=0..15,
 

>          [seq([theta(0)=(Pi*(i/10)), v(0)=2, x(0)=0, y(0)=1 ], i=-2..2)],
 

>         theta=-Pi/2..3*Pi, v=0..3, x=-1..6, y=-1..3,
        scene=[x,y], title="path of glider",
 

>         linecolor=[seq(COLOR(HUE,i/11),i=-2..2)]);
      
 

>
 

Plot_2d
 

> R:=0.3:
motorphug:= [ diff(theta(t),t) = ( v(t)^2 - cos(theta(t))) / v(t),
        diff(v(t),t)     = -sin(theta(t)) - R*v(t)^2 +k,
        diff(x(t),t)     = v(t)*cos(theta(t)),
        diff(y(t),t)     = v(t)*sin(theta(t))];
 

[diff(theta(t), t) = `/`(`*`(`+`(`*`(`^`(v(t), 2)), `-`(cos(theta(t))))), `*`(v(t))), diff(v(t), t) = `+`(`-`(sin(theta(t))), `-`(`*`(.3, `*`(`^`(v(t), 2)))), k), diff(x(t), t) = `*`(v(t), `*`(cos(the...
[diff(theta(t), t) = `/`(`*`(`+`(`*`(`^`(v(t), 2)), `-`(cos(theta(t))))), `*`(v(t))), diff(v(t), t) = `+`(`-`(sin(theta(t))), `-`(`*`(.3, `*`(`^`(v(t), 2)))), k), diff(x(t), t) = `*`(v(t), `*`(cos(the...
(2)
 

> k:=1;DEplot(motorphug, [ theta(t), v(t), x(t), y(t) ], t=0..15,
 

>          [seq([theta(0)=0, v(0)=1+i/3, x(0)=0, y(0)=1 ], i=-5..5)],
 

>         theta=-Pi/2..3*Pi, v=0..3, x=-1..6, y=-1..3,
        scene=[theta,v], title="motor phase",
 

>         linecolor=[seq(COLOR(HUE,i/11),i=-5..5)]);
 

>
 

 

 

1
Warning, plot may be incomplete, the following errors(s) were issued:
  cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up
Plot_2d
 

> k:=0.1;DEplot(motorphug, [ theta(t), v(t), x(t), y(t) ], t=0..15,
 

>          [seq([theta(0)=0, v(0)=1+i/3, x(0)=0, y(0)=1 ], i=-5..5)],
 

>         theta=-Pi/2..3*Pi, v=0..3, x=-1..6, y=-1..3,
        scene=[theta,v], title="motor phase, weak motor",
 

>         linecolor=[seq(COLOR(HUE,i/11),i=-5..5)]);
 

>
 

 

 

.1
Warning, plot may be incomplete, the following errors(s) were issued:
  cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up
Plot_2d
 

> ?
 

> sol:=dsolve({op(xphug), theta(0)=0, v(0)=2, x(0)=0, y(0)=1},
               numeric,  range=0..1);
 

proc (x_rkf45) local res, data, vars, solnproc, outpoint, ndsol, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; `:=`(_EnvDSNumericSaveDigits, Digits); `:=`(Digits, 15); if... (3)
 

> sol(5);
 

[t = 5., theta(t) = -.138321763929649760, v(t) = 1.05397720830789443, x(t) = 4.11407991711292897, y(t) = .404937110660214983]
[t = 5., theta(t) = -.138321763929649760, v(t) = 1.05397720830789443, x(t) = 4.11407991711292897, y(t) = .404937110660214983]
(4)
 

> sol(6);
 

[t = 6., theta(t) = -.190101442192956577, v(t) = .910406559975140972, x(t) = 5.07485488986160327, y(t) = .270247369708244700]
[t = 6., theta(t) = -.190101442192956577, v(t) = .910406559975140972, x(t) = 5.07485488986160327, y(t) = .270247369708244700]
(5)
 

> sol(7);
 

[t = 7., theta(t) = -.338782751184794895, v(t) = .931013203801475453, x(t) = 5.94984521238635633, y(t) = 0.255416556724448116e-1]
[t = 7., theta(t) = -.338782751184794895, v(t) = .931013203801475453, x(t) = 5.94984521238635633, y(t) = 0.255416556724448116e-1]
(6)
 

> sol(8);
 

[t = 8., theta(t) = -.343744243180552689, v(t) = .995935709444675688, x(t) = 6.85687226318166143, y(t) = -.308165432458417321]
[t = 8., theta(t) = -.343744243180552689, v(t) = .995935709444675688, x(t) = 6.85687226318166143, y(t) = -.308165432458417321]
(7)
 

> sol(7.5);
 

[t = 7.5, theta(t) = -.358222771576701626, v(t) = .968084173509323631, x(t) = 6.39555820098858518, y(t) = -.138186364902548459]
[t = 7.5, theta(t) = -.358222771576701626, v(t) = .968084173509323631, x(t) = 6.39555820098858518, y(t) = -.138186364902548459]
(8)
 

> sol(7.25);
 

[t = 7.25, theta(t) = -.353719631020793346, v(t) = .949755892493055698, x(t) = 6.17089436572355776, y(t) = -0.544459449198846299e-1]
[t = 7.25, theta(t) = -.353719631020793346, v(t) = .949755892493055698, x(t) = 6.17089436572355776, y(t) = -0.544459449198846299e-1]
(9)
 

> sol(7.125);
 

[t = 7.125, theta(t) = -.347632227615635336, v(t) = .940277524903777917, x(t) = 6.05996636374467101, y(t) = -0.138400353427002975e-1]
[t = 7.125, theta(t) = -.347632227615635336, v(t) = .940277524903777917, x(t) = 6.05996636374467101, y(t) = -0.138400353427002975e-1]
(10)
 

> sol(7.1);
 

[t = 7.1, theta(t) = -.346086191043467883, v(t) = .938396310159208880, x(t) = 6.03788159224965604, y(t) = -0.585674392844118610e-2]
[t = 7.1, theta(t) = -.346086191043467883, v(t) = .938396310159208880, x(t) = 6.03788159224965604, y(t) = -0.585674392844118610e-2]
(11)
 

> sol(7.05);
 

[t = 7.05, theta(t) = -.342659162500944914, v(t) = .934670564705084139, x(t) = 5.99380508666551660, y(t) = 0.995383412486241029e-2]
[t = 7.05, theta(t) = -.342659162500944914, v(t) = .934670564705084139, x(t) = 5.99380508666551660, y(t) = 0.995383412486241029e-2]
(12)
 

> yt:= T->subs(sol(T), y(t));
 

proc (T) options operator, arrow; subs(sol(T), y(t)) end proc (13)
 

> yt(7.02);
 

0.193343876903720388e-1 (14)
 

> bisector := proc( f, low, high, epsilon)
  local mid, lo, hi;
  lo := low;
  hi := high;
  mid := (lo+hi)/2;
  while ( abs(f(mid))>epsilon) do
     if ( f(mid) > 0) then
        hi:= mid;
     else
        lo:= mid;
     fi;
     mid := (lo+hi)/2;
  od;
  return(mid);
end:
 

let's test it for something we know the answer. 

> bisector(2*x-1, 0, 1, 0.001);
 

Error, (in bisector) cannot determine if this expression is true or false: 0.1e-2 < abs(2*x(1/2)-1)
 

> bisector(2*x-1, 0, 5, 0.001);
 

Error, (in bisector) cannot determine if this expression is true or false: 0.1e-2 < abs(2*x(5/2)-1)
 

> bisector(x->2*x-1, 0, 5, 0.001);
 

`/`(1025, 2048) (15)
 

> evalf(%);
 

.5004882812 (16)
 

Ramon prefers decimals 

> bisector := proc( f, low, high, epsilon)
  local mid, lo, hi;
  lo := evalf(low);
  hi := evalf(high);
  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;
  od;
  return(mid);
end:
 

> bisector(x->x^2-1, 0, 5, 0.001);
 

.9997558590 (17)
 

> bisector(yt, 8, 7, 0.00001);
 

7.081542969 (18)
 

> yt(7.081542969);
 

0.440496148001631491e-5 (19)
 

> bisector := proc( f, low, high, epsilon)
  local mid, lo, hi;
  lo := evalf(low);
  hi := evalf(high);
  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:
 

> bisector(yt, 8, 7, 0.001);
 

 

 

 

 

 

 

 

[7.500000000, 7.], 7.250000000,
[7.250000000, 7.], 7.125000000,
[7.125000000, 7.], 7.062500000,
[7.125000000, 7.062500000], 7.093750000,
[7.093750000, 7.062500000], 7.078125000,
[7.093750000, 7.078125000], 7.085937500,
[7.085937500, 7.078125000], 7.082031250,
7.082031250 (20)
 

Don't try this at home, kids!
it runs forever and is hard to interrupt.
 

> # bisector(yt, 7, 8, 0.001);
 

 

 

 

 

 

 

 

 

 

 

[7.500000000, 8.], 7.750000000,
[7.750000000, 8.], 7.875000000,
[7.875000000, 8.], 7.937500000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
[8.000000000, 8.], 8.000000000,
Warning,  computation interrupted
 

> bisector := proc( f, low, high, epsilon)
  local mid, lo, hi;
  lo := evalf(low);
  hi := evalf(high);
  if (abs(f(lo))>0) then error("f not neg at lo=",lo); fi;
  if (abs(f(hi))>0) then error("f not pos at hi=",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:
 

> bisector(yt, 7, 8, 0.001);
 

Error, (in bisector) f not neg at lo=, 7.
 

>