function [L,Vee] =lengthvar(R,X,T,M)

gamma = 50;
h=1;
g1 = 0.0756;
gp1 = 0.0709;
fp1 = 0.2838;
g2=20.*g1;
gx=g2.*(X<0)+g1.*(X).*(X>=0 & X<=h)+ (g1).*(X>h);
gpx= 3*(fp1+gp1).*(X<0)+gp1.*(X).*(X>=0 & X<=h)+(4*gp1).*(X).*(X>h);
fpx=0.*(X<0)+fp1.*(X).*(X>=0 & X<=h)+0.*(X>h);
    
n1=R(1:M);
n2=R( (M+1):(2*M));
n3=R( (2*M+1):(3*M));
n4=R( (3*M+1):(4*M));



Vee = (gamma*(trapz(X,X.*fpx.*n2)-trapz(X,gx.*n3)-trapz(X,gpx.*n4)))/(1+gamma*(trapz(X,n3+n4)));
L = trapz(T,Vee);
% L=1*(t<=180)+(1+(0.01*sin(2*pi*f*t)))*(t>180 && t<=245)+(1+(0.04*sin(2*pi*f*t)))*(t>245);
% gamma=25;
% 
% alpha=gamma*(L-1);

%This
%is the V to use for DM

%   V=(-2*pi*gamma*0.01*f*cos(2*pi*f*t))*(t>180 && t<=245)+(-2*pi*gamma*0.04*f*cos(2*pi*f*t))*(t>245);