% le script du cours 3
clf; clear all;

% surface en 3D
n=70;
x=linspace(-5,5,n);
y=linspace(-5,5,n)

for t=linspace(0,4*2*pi,1000);

f=zeros(n,n);
for indx=1:n
    for indy=1:n;
        f(indx,indy)=sin(t+3*y(indy))*exp(-x(indx)^2-y(indy)^2);
    end
end

mesh(x,y,f);
zlim([-1,1]);
caxis([-1,1]);
drawnow;
end



xlabel('x')
ylabel('y')
zlabel('z')



break
% exemple de plot3
phivec=linspace(0,3*2*pi,300);
for ind=1:length(phivec);
    phi=phivec(ind);
    
th=linspace(0,5*2*pi,1000);
r=1.1*th;
x=r.*cos(th+phi);
y=r.*sin(th+phi);
plot(x,y);


z=r;
hold on
plot3(x,y,z,'r');
view(3)
grid on
hold off
drawnow

end


break
% l'exemple de la poutre pour estimer B
subplot(2,1,1);
d=load('datapoutre.txt');
x=d(:,1); y=d(:,2);

plot(x,y,'b.-');
xlabel('x'); ylabel('y');


% LE MODELE LINéAIRE
g=9.81;
lambda=0.45; 
L=0.055;

Bvec=linspace(0.0001,0.001,200);
Bvec=2.55e-4;
emem=0*Bvec;

%Bvec=0.0001;
for ind=1:length(Bvec);
    
B=Bvec(ind);
subplot(2,1,1);
ytheo=-lambda*g*((x-L).^4/4+x.*L^3-L^4/4)/(6*B);
hold on
plot(x,ytheo,'r.-');

text(L,ytheo(1),num2str(B))

% mesure de l'erreur
emem(ind)=sum((y-ytheo).^2);

end

subplot(2,1,2);
plot(Bvec,emem,'b-');



break

% exemple d'opérations binaires
nvec=2:100:50000;
for ind=1:length(nvec)
n=nvec(ind);
    
a=randn(1,n);

b=a>0;
npos=sum(b)/n;

plot(n,npos,'b.');
hold on
ylim([0,1]);
end





break
% exemple de selection

n=101;
x=linspace(-5,5,n);
f=exp(-x.^2).*cos(3*x);

%plot(x,f,'r.-')

seli=1:2:n;
selp=2:2:n;
plot(x(seli),f(seli),'b.');
hold on
plot(x(selp),f(selp),'r.');



