//
///////////////// EXERCICE 1 //////////////////
xset('window',0)
xbasc();
x=0:0.1:2*%pi;y1=sin(x);y2=sin(2*x);
plot2d(x,y1,-1,rect=[0,-2,7,2]);
plot2d(x,y2,3);
legends(['fonction sinus(x)';'x->sin(2x)'],[-1,3],3);
//
///////////////// EXERCICE 2 //////////////////
function y=volterra(t,x)
y(1)=x(1)*x(2)-x(1)/2
y(2)=-x(1)*x(2)+x(2)
endfunction
//
t=0:0.1:25;
u=ode([2;2],0,t,volterra)
xset('window',1);
xbasc()
plot2d(t,u(1,:));
plot2d(t,u(2,:),2);
legends(['predateurs';'proies'],[1,2],3)
xset('window',2)
xbasc()
plot2d(u(1,:),u(2,:))
///////////////// EXERCICE 3 //////////////////
function y=chaine(t,x)
y(1)=x(2);
y(2)=sqrt(1+x(2)^2);
endfunction
//
function u1=Phi(a);
n=20;t=0:1/n:1;
u=ode([0;a],0,t,chaine);
u1=u(1,n+1);
endfunction
//
function x0=dicho(f,amin,amax,epsilon)
f1=f(amin);f2=f(amax);
while(amax-amin>epsilon)
 c=(amin+amax)/2;f3=f(c);
 if(f1*f3<0) then amax=c;else amin=c;end
end
x0=(amin+amax)/2;
endfunction
//
amin=-3;amax=3;a=dicho(Phi,amin,amax,1E-6)
//
n=20;t=0:1/n:1;
u=ode([0;a],0,t,chaine);
xset('window',3)
xbasc();
plot2d(t,u(1,1:n+1))



