clc
clear all
f=dsolve('cos(t)*(sin(pi*t/T)^2)==D2y');
syms T theta R y0 y0d x0 x0d t x y
s=diff(f,t);
f0=subs(f,T,35);
syms C5 C4
C5=solve(subs(f0,t,0)==y0,C5);
df=diff(f,t);
dff=subs(df,T,35);
C4=solve(subs(dff,t,0)==y0d,C4);
f1=eval(f);
f2=x0+t*x0d;
f3=subs(f1,t,(x-x0)/x0d);
s0=subs(eval(s),t,(x-x0)/x0d);
u=subs(s0,T,35);
u=subs(u,y0,R*sin(theta));
u=subs(u,x0,R*cos(theta));
u=subs(u,R,1);
f4=subs(f3,y0,R*sin(theta));
f4=subs(f4,x0,R*cos(theta));
f4=subs(f4,T,35);
f4=subs(f4,R,1);
d=1000;
c=0;
h=1;
for i=1:100
x0d=2*(rand-0.5);
y0d=2*(rand-0.5);
theta=rand*pi;
g=eval(f4);
u0=eval(u);
if atan(abs(cot(theta)))+atan(abs(y0d/x0d))<=pi/2
c(h)=solve(g==d);
m(h)=subs(eval(u),x,c(h));
XD(h)=x0d;
h=h+1;
end
end
cmin=min(c);
cmax=max(c);
k=linspace(-10000,10000,1000);
cc=hist(c,k);
cc=cc/length(c);
bar(k,cc)
dd=hist3(XD,m,k);
bar3(XD,m)