function theta_d=fun_f(t,theta)
theta_d(1:n)=theta(n+1:2*n);
a(i,j)= - m_(j)/m_(i)* L(j)/L(i)* cos(theta(i)-theta(j));
b_(i,j)= - m_(j)/m_(i)* L(j)/L(i)* theta_d(j)^2* sin(theta(i)-theta(j));
a(i,j)= - L(j)/L(i)* cos(theta(j)-theta(i));
b_(i,j)= L(j)/L(i)* theta_d(j)^2* sin(theta(j)-theta(i));
b_(i,j)= -g/L(i)* sin(theta(i));
m=[linspace(0.01, 0.01, n)];
L=[linspace(0.2, 0.2, n)];
theta0=[linspace(0.5, 1.0, n)];
theta_dot0=[linspace(0, 0, n)];
dt=0.01; tmax=10; tspan=[0:dt:tmax];
[t theta]=ode45(@fun_f, tspan, ini);
x=zeros(numel(tspan),n);y=zeros(numel(tspan),n);
x(:,i)=x(:,i-1)+L(i)*sin(theta(:,i));
y(:,i)=y(:,i-1)-L(i)*cos(theta(:,i));
x(:,i)=L(i)*sin(theta(:,i));
y(:,i)=-L(i)*cos(theta(:,i));
plot([0 x(k,:)], [0 y(k,:)]);
axis([-sum(L) sum(L) -sum(L) sum(L)]);
theta_d(1:n)=theta(n+1:2*n);