help me solve this...what i need is if anybody can change this codes from part 2 to part 5 but still use the same concept. the output must in negative and positive value. pls email me..cinok777@yahoo.com

% PART I --------The calculation of deflection and effective stiffness for a force at One End------


format long
A=7183e-6; %Rail properties based on British Section BS 113 A
E=200e9;
l=0.6;
T=20e6;

k=A*E/l;
k1=2.15e8;
k2=2.15e8;

d1=0.001; %The calculation of rail deflection, force and stiffness from left hand side
d2=(1+(k1/k))*d1; % of the track
dLeft=[d1 d2];


S= input(' Enter the number of sleeper panels for the whole track: ')

for s=2:S;
dLeft(s+1)=(2+(T/k))*dLeft(s)-dLeft(s-1);
end

for s=2:S+1;
FLeft(s)=k*((1+(T/k))*dLeft(s)-dLeft(s-1));
end

dLeft;
FLeft;
FdLeft=FLeft./dLeft;

%The calculation of rail deflection, force and stiffness from the right hand side of
%the track
%Specify deflection at node S and calculate deflection for the rest of the
%track i.e from S-1 to node 1. Calculate forces for node S to node 1 and
%divide force over deflection to get stiffness

dS=0.001;
dM=(1+(k2/k)+(T/k))*dS;


dRight=[dS dM];

for M=3:S;
dRight(M)=(2+(T/k))*dRight(M-1)-dRight(M-2);
end

for M=2:S;
FRight(M)=k*(dRight(M)-dRight(M-1));
end

dRight;
FRight;
FdRight=FRight./dRight;

%Program section II
%---Sleeper J For Locomotives And Wagons------

%Define wagon and locomotive arrangement.

Wagon= input ('Enter the number of wagons:')
Loco=input('Enter the number of locomotives:')
Axle_w=2;
Axle_l=2;

%Define the first sleeper panel of the train and the number of sleepers
%between each axle of the locomotives/wagon.

s1=input('Enter the first sleeper panel(wagon):')
sw_1=input('Enter the number of sleepers within wagon:')
sw_2=input('Enter the number of sleepers between wagons:')
sl_1=input('Enter the number of sleepers within locomotives:')
sl_2=input('Enter the number of sleepers between locomotives:')


%Generate sleeper panel for wagon.
%Specify first sleeper panel of the wagon and genarate list of sleeper
%panel by counting the number of sleepers between athe axles of the wagon.

sw1=s1;

for w=0:Wagon-1
Swag1(w+1)=sw1+w*(sw_1+sw_2);
Swag2(w+1)=sw1+w*(sw_1+sw_2)+(sw_1);
Sw=sort([Swag1 Swag2]);
end

%Generate sleeper panel for locomotive.
%Specify first sleeper panel of locomotive and generate list of sleeper
%panels by counting the number of sleeper between the axles of the
%locomotive.

sl1=Sw(Wagon*Axle_w);

for l=0:Loco-1
Sloco1(l+1)=sl1+l*(sl_1+sl_2);
Sloco2(l+1)=sl1+l*(sl_2+sl_2)+(sl_1);
Sl=sort([Sloco1 Sloco2]);
end

%generate force for unit displacement at sleeper J - left hand side and
%right hand side
%calculate the reciprocal of the total force at sleeper J
%Calculate scale factor for force on the left hand side and right hand side
%of the track

%---Wagon---

FdLeft(Sw);
FdRight(S-Sw+1);
Df=1./(FdLeft(Sw)+FdRight(S-Sw+1));
SLeft_w=Df./dLeft(Sw);
SRight_w=Df./dRight(S-Sw+1);

%----Locomotive----
FdLeft(Sl);
FdRight(S-Sl+1);
Df=1./(FdLeft(Sl)+FdRight(S-Sl+1));
SLeft_l=Df./dLeft(Sl);
SRight_l=Df./dRight(S-Sl+1);


%Program section III
%------Deflection at Sleeper J----------

%Calculate deflection at sleeper J(Left and side and Right hand side)

%calculate deflection at a sleeper J by multiplying deflection at every
%sleeper at node x by the scale factor. Repeat this for every sleeper J for
%both wagons and locomotives. Calculate for deflection from the left hand
%side and the right hand side of the track.Calculate total deflection for
%wagons and locomotives seperately.

%Generates an i by x matrix where the elements of each column of the matrix
%are the deflection at a node X for i number of sleepers for wagons/locomotives.
%Take the sum of the all elements of each column of te matrix to obtain
%total deflection

%----Left Hand Side Wagon-----
for i=1:Wagon*Axle_w
for x=1:Sw(i)-1
dLeft_w(i,x)=SLeft_w(i)*dLeft(x);
end
end

dLeft_wt=sum(dLeft_w)';

%----Left hand side locomotive-----

for i=1:Loco*Axle_l
for x=1:Sl(i)-1
dLeft_l(i,x)=SLeft_l(i)*dLeft(x);
end
end

dLeft_lt=sum(dLeft_l)';

%----Right hand side wagon------
for i=1:Wagon*Axle_w
for x=1:S-Sw(i)+1
dRight_w(i,x)=SRight_w(i)*dRight(x);
end
end

%----Right hand side locomotive-----

dRight_wt=sum(dRight_w)';

%Deflection for locomotive
for i=1:Loco*Axle_l
for x=1:S-Sl(i)+1
dRight_l(i,x)=SRight_l(i)*dRight(x);
end
end

dRight_lt=sum(dRight_l)';

%Program Section IV-----
%^^^^^^^^^^^^^^^^^^^^^Total Deflection For Train^^^^^^^^^^^^^^^^^^^^^^

%Calculate scaled deflection and total deflection for wagons, locomotives
%and the entire train

%Specify the amount of force applied on the sleeper by the train. Calculate
%the scaled deflection for left hand side and right hand side.
%Redimension matrix to enable sum of two matrix.For left hand side
%deflections give zero value to elements of the final sleeper J of
%wagon/locomotive to the last sleeper N of track. For right hand side
%deflection give zero value to element of sleepers at node 1 of track to
%the last sleeper before sleeper J of wagon/locomotive
%Calculate total deflection of wagon/locomotive

%^^^^^^Wagon^^^^^^^

%Scale deflection

Fw=input('Specify the force applied by wagon per axle:')
dLeft_ws=dLeft_wt*Fw;
dRight_ws=dRight_wt*Fw;

%Redimension matrix

dLeft_wsnew=dLeft_ws;
for i= Sw(Wagon*Axle_w):S;
dLeft_wsnew(i)=0;
end
dLeft_wsnew;

dRight_wsnew1=dRight_ws;
for i=S-sw1+2:S;
dRight_wsnew1(i)=0
end
dRight_wsnew=flipud(dRight_wsnew1);

%Total deflection

dT_w=dLeft_wsnew+dRight_wsnew;

%-----Locomotive-------

%Scale deflection

Fl=input('Specify the force applied by locomotive per axle:')
dLeft_ls=dLeft_lt*Fl;
dRight_ls=dRight_lt*Fl;

%Redimension matrix

dLeft_lsnew=dLeft_ls;
for i= Sl(Loco*Axle_l):S;
dLeft_lsnew(i)=0;
end
dLeft_lsnew;

dRight_lsnew=dRight_ls;
for i=S-Sl(1)+2:S;
dRight_lsnew(i)=0;
end
dRight_lsnew=flipud(dRight_lsnew);

%Total deflection

dT_l=dLeft_lsnew+dRight_lsnew;

%Calculate total deflection for entire train

dT=dT_w+dT_l

%Program V-----------------
%^^^^^^^^^^^^^^^^^Plot Displacement Pattern of Rail^^^^^^^^^^^^^

plot(dT_w,'--k')
hold on
plot(dT_l,'--r')
hold on
plot(dT,'b')
axis auto
xlabel('Sleeper')
ylabel('Displacement (m)')
title('Displacement Pattern in Rail')
legend('Wagon','Locomotive','Train')

Lets make it simple and to the point.
1. This is C# not C++ forum
2. Read the forum rules.. we dont do your homework for you
3. If you want help then post code using the code tags, and ask specific questions giving specific error messages at specific points if you have them, also saying what you have tried and we will help gladly

This article has been dead for over six months. Start a new discussion instead.