You are on page 1of 24

Name: Harshit Rai

Roll No: 09/MCE/19 (M.Tech – 1st Semester Transportation)


College: World College Of Technology & Management

Computational Laboratory file [CE 681]


Experiment - 1
Calculation of deflection at section along beam

//-----------------------------------------------
// CALCULATE DEFLECTIONS AT SECTIONS ALONG BEAM
//-----------------------------------------------
// Deflection = Integral (ms[k1].mx)/EI dx

// Simpson's Rule:
// Integral ydx = (s/3).[(Sum of end ordinates +
// 4(sum of even ordinates) + 2(sum of odd
ordinates)]
// where s = length of increment between sections
considered.
// i.e. for 20m span with 21 sections s = 20/(21-1)
= 1.

//SET UP SIMPSONS' ORDINATES AS SIMPSON'S RULE


// Must be an even number of spaces (21 sections:
20 spaces)
// If section is an even number then multiplier
s[k1] of
// BM due to Unit Load is 4. If it is odd number
// multiplier is 2.
s1[1] = 0;
s1[ns] = 0;
for (int k = 2;k<=ns;++k) {
if(k % 2 == 0) { // check for even
number
s1[k] = 4;
}
else {
s1[k] = 2; // if not even number, it is
odd number
}
}

//NUMERICAL INTEGRATION

for (int k=1; k <= ns; ++k) {


dk = 0;
zd = (k-1) * L/(ns-1);
for(int k1 = 1; k1 <= ns; ++k1) {
// UNIT LOAD MOMENTS
// Set up and calculate moments due to
// Unit Loads at relevant sections

By: Harshit Rai


Page 1 of 23
// along the beam
z = (k1 - 1) * L/(ns-1);

if(z<=zd) {
mx = z * (L - zd)/L;
}
else {
if(z>zd) {
mx = zd * (L - z)/L;
}
}

// SUMMING MOMENT PRODUCTS AND SIMPSONS'


ORDINATES
// Multiply BM at sections by BM due to
Unit Load
// at each section
dk = dk + ms[k1] * mx * s1[k1];
} // end of scope for loop k1

ds[k] = dk * L * pow(10,12)/(ns-1)/3/i2/ec;

} // end of scope for loop k

//SORT FOR MAXIMUM DEFLECTION AND ITS LOCATION


for(int k = 1; k <= ns; ++k) {
if (ds[k] > dm) {
dm = ds[k];
sd = L * (k - 1)/(ns-1);
}
} // end of scope for loop k for sort max
deflection

By: Harshit Rai


Page 2 of 23
Experiment - 2.
Calculation of shear force, slope and deflection of Continuous
beam

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

class Beam
{
public:
double L, EI;
double V0, dV0;
Beam( double L_ = 1.0, double EI_ = 1.0 ) : L( L_ ), EI(
EI_ ) {}
};

class PLoad
{
public:
double x, W;
PLoad( double x_ = 0.0, double W_ = 0.0 ) : x( x_ ), W( W_
) {}
};

class CLoad
{
public:
double xl, xr, wl, wr;
double dx, dwdx;
CLoad( double XL = 0.0, double XR = 1.0, double WL = 0.0,
double WR = 0.0 ) : xl( XL ), xr( XR ), wl( WL ), wr( WR )
{
dx = xr - xl;
dwdx = ( wr - wl ) / dx;
}
};

class React
{
public:
double x;
char type;

By: Harshit Rai


Page 3 of 23
double v;
double R;
React( double x_ = 0.0, char T = 'F', double v_ = 0.0 ) :
x( x_ ), type( T ), v( v_ ) {}
};

class Monitor
{
public:
double x;
double v, dvdx, S, M;
Monitor( double X = 0.0 ) : x( X ) {}
};

//

Beam beam;
vector<PLoad> load;
vector<CLoad> cont;
vector<React> react;
vector<Monitor> pt;

void prob();
void init();
void calc();
void outp();
double Defl( double x );
double Grad( double x );
double BM( double x );
double SF( double x );
double Vnr( double x );
double dVnr( double x );
double Mnr( double x );
double Snr( double x );
double loadInt( double x, int p );
double Mac( double x, double x0, int n );

//

int main()
{
init();
prob();
calc();
outp();
}

//

void prob()
{

By: Harshit Rai


Page 4 of 23
// Beam
double L = 20000.0, E = 25000.0, I = 7.2e9;
beam = Beam( L, E * I );

// Loads
load.push_back( PLoad( L / 2.0, 3.0e4 ) ); // pt
// cont.push_back( CLoad( 0.0, L, 2.5, 2.5 ) ); // UDL

// Reactions
react.push_back( React( 0.0, 'F', 0.0 ) );
react.push_back( React( L , 'F', 0.0 ) );

double x1 = 0.0, x2 = L;
int nx = 20;
double dx = ( x2 - x1 ) / nx;
for ( int i = 0; i <= nx; i++ ) pt.push_back( Monitor( x1 +
i * dx ) );
}

//

void init()
{
beam = Beam( 1.0, 1.0 );
load.clear();
cont.clear();
react.clear();
pt.clear();
}

//

void calc()
{
int i, ii, ibig, j, m, n;
double f, big, temp, xm, xn;
int nR = react.size();
int size = nR + 2;
vector< vector<double> > A( size, vector<double>( size, 0.0
) );
vector<double> b( size, 0.0 );
vector<double> x( size, 0.0 );

// Load
i = 0;
for ( n = 0; n < nR; n++ )
{
if ( react[n].type == 'F' ) A[i][n+2] = 1.0;
}
b[i] = Snr( beam.L );

By: Harshit Rai


Page 5 of 23
// Moment
i = 1;
for ( n = 0; n < nR; n++ )
{
if ( react[n].type == 'M' ) A[i][n+2] = 1.0;
if ( react[n].type == 'F' ) A[i][n+2] = -( beam.L -
react[n].x );
}
b[i] = Mnr( beam.L );

// Constraints
for ( m = 0; m < nR; m++ )
{
xm = react[m].x;
i = m + 2;
if ( react[m].type == 'F' )
{
A[i][0] = 1.0;
A[i][1] = xm;
for ( n = 0; n < nR; n++ )
{
xn = react[n].x;
j = n + 2;
if ( react[n].type == 'M' ) A[i][j] = Mac( xm,
xn, 2 );
if ( react[n].type == 'F' ) A[i][j] = -Mac( xm,
xn, 3 );
}
b[i] = beam.EI * react[m].v - Vnr( xm );
}
if ( react[m].type == 'M' )
{
A[i][0] = 0.0;
A[i][1] = 1.0;
for ( n = 0; n < nR; n++ )
{
xn = react[n].x;
j = n + 2;
if ( react[n].type == 'M' ) A[i][j] = Mac( xm,
xn, 1 );
if ( react[n].type == 'F' ) A[i][j] = -Mac( xm,
xn, 2 );
}
b[i] = beam.EI * react[m].v - dVnr( xm );
}
}

// Solve
// Norm rows
for ( i = 0; i < size; i++ )
{

By: Harshit Rai


Page 6 of 23
big = abs( A[i][0] );
for ( j = 1; j < size; j++ ) big = max( abs( A[i][j] ),
big );
for ( j = 0; j < size; j++ ) A[i][j] = A[i][j] / big;
b[i] = b[i] / big;
}

// Triangular
for ( i = 0; i < size - 1; i++ )
{
// Make A[i][i] largest on diagonal or below
big = abs( A[i][i] );
ibig = i;
for ( ii = i + 1; ii < size; ii++ )
{
temp = abs( A[ii][i] );
if ( temp > big)
{
big = temp;
ibig = ii;
}
}
if ( ibig != i )
{
for ( j = i; j < size; j++ ) swap( A[i][j],
A[ibig][j] );
swap( b[i], b[ibig] );
}

// Pivot
for ( ii = i + 1; ii < size; ii++ )
{
f = A[ii][i] / A[i][i];
for ( j = 0; j < size; j++ ) A[ii][j] -= f * A[i][j];
b[ii] -= f * b[i];
}
}

// Back-sub
for ( i = size - 1; i >= 0; i-- )
{
x[i] = b[i];
for ( j = i + 1; j < size; j++ ) x[i] -= A[i][j] * x[j];
x[i] /= A[i][i];
}

beam.V0 = x[0];
beam.dV0 = x[1];
for ( n = 0; n < nR; n++ )
{
i = n + 2;

By: Harshit Rai


Page 7 of 23
react[n].R = x[i];
}
}

//

void outp()
{
#define SP << setw( 15 ) <<

for ( int n = 0; n < pt.size(); n++ )


{
double x = pt[n].x;
pt[n].v = Defl( x );
pt[n].dvdx = Grad( x );
pt[n].S = SF ( x );
pt[n].M = BM ( x );
}

cout << "Beam:\n";


cout << " L: " << beam.L << '\n';
cout << " EI: " << beam.EI << '\n';
cout << '\n';

cout << "Point loads:\n" SP "x" SP "Value" << '\n';


for ( int i = 0; i < load.size(); i++ ) cout SP load[i].x
SP load[i].W << '\n';
cout << '\n';

cout << "Cont. loads:\n" SP "xl" SP "xr" SP "wl" SP "wr" <<


'\n';
for ( int i = 0; i < cont.size(); i++ ) cout SP cont[i].xl
SP cont[i].xr SP cont[i].wl SP cont[i].wr << '\n';
cout << '\n';

cout << "Reactions:\n" SP "x" SP "Type" SP "Value" << '\n';


for ( int i = 0; i < react.size(); i++ ) cout SP react[i].x
SP react[i].type SP react[i].R << '\n';
cout << '\n';

cout << "Monitors:\n" SP "Num" SP "x" SP "S" SP "M" SP


"slope" SP "down" << '\n';
for ( int i = 0; i < pt.size(); i++ )
cout SP i SP pt[i].x SP pt[i].S SP pt[i].M SP
pt[i].dvdx SP pt[i].v << '\n';
}

//

double Defl( double x )


{

By: Harshit Rai


Page 8 of 23
double val = Vnr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val += react[n].R * Mac( x,
react[n].x, 2 );
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 3 );
}
val += beam.dV0 * x + beam.V0;
return val / beam.EI;
}

//

double Grad( double x )


{
double val = dVnr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val += react[n].R * Mac( x,
react[n].x, 1 );
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 2 );
}
val += beam.dV0;
return val / beam.EI;
}

//

double BM( double x )


{
double val = Mnr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val -= react[n].R * Mac( x,
react[n].x, 0 );
if ( react[n].type == 'F' ) val += react[n].R * Mac( x,
react[n].x, 1 );
}
return val;
}

//

double SF( double x )


{
double val = Snr( x );
for ( int n = 0; n < react.size(); n++ )
{

By: Harshit Rai


Page 9 of 23
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 0 );
}
return val;
}

//

double Vnr( double x )


{
return loadInt( x, 4 );
}

//

double dVnr( double x )


{
return loadInt( x, 3 );
}

//

double Mnr( double x )


{
return -loadInt( x, 2 );
}

//

double Snr( double x )


{
return loadInt( x, 1 );
}

//

double loadInt( double x, int p ) // pth integral of load


{
double val = 0.0;
for ( int n = 0; n < load.size(); n++ )
{
val += load[n].W * Mac( x, load[n].x, p - 1 );
}
for ( int n = 0; n < cont.size(); n++ )
{
val += cont[n].wl * ( Mac( x, cont[n].xl, p ) -
Mac( x, cont[n].xr, p ) );
val += cont[n].dwdx * ( Mac( x, cont[n].xl, p + 1 ) -
Mac( x, cont[n].xr, p + 1 ) - cont[n].dx * Mac( x, cont[n].xr,
p ) );
}

By: Harshit Rai


Page 10 of 23
return val;
}

//

double Mac( double x, double x0, int n ) // Macaulay bracket


& integrals
{
double xx = x - x0;

if ( xx < 0 ) return 0.0;


if ( n == 0 ) return 1.0;

double val = xx;


for ( int i = 2; i <= n; i++ ) val *= xx / i;
return val;
}

By: Harshit Rai


Page 11 of 23
Experiment – 3
Simply Supported beam with a general located point load
calculation of shear force, bending moment, slope, deflection

void P_SS::P_SS::prepare_table(){

double L = m_beam.L;
double slope = 0.0;
double deflection = 0.0;

Ra = P * (L - a) / L; // reaction end a
Rb = P - Ra; // reaction end b

double x = 0.0;
double V = 0.0;
double BM = 0.0;

double EI = m_beam.E * m_beam.I;


double C1 = -Ra*L*L/6 + P*(L-a)*(L-a)*(L-a)/(6*L);

for(int i = 0; i <= m_beam.no_segments; ++i){

x = i * m_beam.dx;

if(x <= a){

V = Ra;
BM = Ra * x;
slope = (Ra*x*x/2 + C1)/EI;
deflection = (Ra*x*x*x/6 + C1*x)/EI;
}
else{ // Macaulay - to do better one day :)

V = Ra - P;
BM = Ra * x - P * (x - a);
slope = (Ra*x*x/2 - P*(x-a)*(x-a)/2 + C1)/EI;
deflection = (Ra*x*x*x/6 - P*(x-a)*(x-a)*(x-a)/6 +
C1*x)/EI;
}
actions.push_back(std::make_tuple(V, BM, slope,
deflection));
}
}

By: Harshit Rai


Page 12 of 23
Experiment – 4
Calculation of Flow in Pipe

//-----------------------------------------------
// CALCULATE DEFLECTIONS AT SECTIONS ALONG BEAM
//-----------------------------------------------
// Deflection = Integral (ms[k1].mx)/EI dx

// Simpson's Rule:
// Integral ydx = (s/3).[(Sum of end ordinates +
// 4(sum of even ordinates) + 2(sum of odd
ordinates)]
// where s = length of increment between sections
considered.
// i.e. for 20m span with 21 sections s = 20/(21-1)
= 1.

//SET UP SIMPSONS' ORDINATES AS SIMPSON'S RULE


// Must be an even number of spaces (21 sections:
20 spaces)
// If section is an even number then multiplier
s[k1] of
// BM due to Unit Load is 4. If it is odd number
// multiplier is 2.
s1[1] = 0;
s1[ns] = 0;
for (int k = 2;k<=ns;++k) {
if(k % 2 == 0) { // check for even
number
s1[k] = 4;
}
else {
s1[k] = 2; // if not even number, it is
odd number
}
}

//NUMERICAL INTEGRATION

for (int k=1; k <= ns; ++k) {


dk = 0;
zd = (k-1) * L/(ns-1);
for(int k1 = 1; k1 <= ns; ++k1) {
// UNIT LOAD MOMENTS
// Set up and calculate moments due to

By: Harshit Rai


Page 13 of 23
// Unit Loads at relevant sections
// along the beam
z = (k1 - 1) * L/(ns-1);

if(z<=zd) {
mx = z * (L - zd)/L;
}
else {
if(z>zd) {
mx = zd * (L - z)/L;
}
}

// SUMMING MOMENT PRODUCTS AND SIMPSONS'


ORDINATES
// Multiply BM at sections by BM due to
Unit Load
// at each section
dk = dk + ms[k1] * mx * s1[k1];
} // end of scope for loop k1

ds[k] = dk * L * pow(10,12)/(ns-1)/3/i2/ec;

} // end of scope for loop k

//SORT FOR MAXIMUM DEFLECTION AND ITS LOCATION


for(int k = 1; k <= ns; ++k) {
if (ds[k] > dm) {
dm = ds[k];
sd = L * (k - 1)/(ns-1);
}
} // end of scope for loop k for sort max
deflection

By: Harshit Rai


Page 14 of 23
Experiment – 5
Calculation for Viscosity of Fluid

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

class Beam
{
public:
double L, EI;
double V0, dV0;
Beam( double L_ = 1.0, double EI_ = 1.0 ) : L( L_ ), EI(
EI_ ) {}
};

class PLoad
{
public:
double x, W;
PLoad( double x_ = 0.0, double W_ = 0.0 ) : x( x_ ), W( W_
) {}
};

class CLoad
{
public:
double xl, xr, wl, wr;
double dx, dwdx;
CLoad( double XL = 0.0, double XR = 1.0, double WL = 0.0,
double WR = 0.0 ) : xl( XL ), xr( XR ), wl( WL ), wr( WR )
{
dx = xr - xl;
dwdx = ( wr - wl ) / dx;
}
};

class React
{
public:
double x;
char type;
double v;
double R;

By: Harshit Rai


Page 15 of 23
React( double x_ = 0.0, char T = 'F', double v_ = 0.0 ) :
x( x_ ), type( T ), v( v_ ) {}
};

class Monitor
{
public:
double x;
double v, dvdx, S, M;
Monitor( double X = 0.0 ) : x( X ) {}
};

//

Beam beam;
vector<PLoad> load;
vector<CLoad> cont;
vector<React> react;
vector<Monitor> pt;

void prob();
void init();
void calc();
void outp();
double Defl( double x );
double Grad( double x );
double BM( double x );
double SF( double x );
double Vnr( double x );
double dVnr( double x );
double Mnr( double x );
double Snr( double x );
double loadInt( double x, int p );
double Mac( double x, double x0, int n );

//

int main()
{
init();
prob();
calc();
outp();
}

//

void prob()
{
// Beam
double L = 20000.0, E = 25000.0, I = 7.2e9;

By: Harshit Rai


Page 16 of 23
beam = Beam( L, E * I );

// Loads
load.push_back( PLoad( L / 2.0, 3.0e4 ) ); // pt
// cont.push_back( CLoad( 0.0, L, 2.5, 2.5 ) ); // UDL

// Reactions
react.push_back( React( 0.0, 'F', 0.0 ) );
react.push_back( React( L , 'F', 0.0 ) );

double x1 = 0.0, x2 = L;
int nx = 20;
double dx = ( x2 - x1 ) / nx;
for ( int i = 0; i <= nx; i++ ) pt.push_back( Monitor( x1 +
i * dx ) );
}

//

void init()
{
beam = Beam( 1.0, 1.0 );
load.clear();
cont.clear();
react.clear();
pt.clear();
}

//

void calc()
{
int i, ii, ibig, j, m, n;
double f, big, temp, xm, xn;
int nR = react.size();
int size = nR + 2;
vector< vector<double> > A( size, vector<double>( size, 0.0
) );
vector<double> b( size, 0.0 );
vector<double> x( size, 0.0 );

// Load
i = 0;
for ( n = 0; n < nR; n++ )
{
if ( react[n].type == 'F' ) A[i][n+2] = 1.0;
}
b[i] = Snr( beam.L );

// Moment
i = 1;

By: Harshit Rai


Page 17 of 23
for ( n = 0; n < nR; n++ )
{
if ( react[n].type == 'M' ) A[i][n+2] = 1.0;
if ( react[n].type == 'F' ) A[i][n+2] = -( beam.L -
react[n].x );
}
b[i] = Mnr( beam.L );

// Constraints
for ( m = 0; m < nR; m++ )
{
xm = react[m].x;
i = m + 2;
if ( react[m].type == 'F' )
{
A[i][0] = 1.0;
A[i][1] = xm;
for ( n = 0; n < nR; n++ )
{
xn = react[n].x;
j = n + 2;
if ( react[n].type == 'M' ) A[i][j] = Mac( xm,
xn, 2 );
if ( react[n].type == 'F' ) A[i][j] = -Mac( xm,
xn, 3 );
}
b[i] = beam.EI * react[m].v - Vnr( xm );
}
if ( react[m].type == 'M' )
{
A[i][0] = 0.0;
A[i][1] = 1.0;
for ( n = 0; n < nR; n++ )
{
xn = react[n].x;
j = n + 2;
if ( react[n].type == 'M' ) A[i][j] = Mac( xm,
xn, 1 );
if ( react[n].type == 'F' ) A[i][j] = -Mac( xm,
xn, 2 );
}
b[i] = beam.EI * react[m].v - dVnr( xm );
}
}

// Solve
// Norm rows
for ( i = 0; i < size; i++ )
{
big = abs( A[i][0] );

By: Harshit Rai


Page 18 of 23
for ( j = 1; j < size; j++ ) big = max( abs( A[i][j] ),
big );
for ( j = 0; j < size; j++ ) A[i][j] = A[i][j] / big;
b[i] = b[i] / big;
}

// Triangular
for ( i = 0; i < size - 1; i++ )
{
// Make A[i][i] largest on diagonal or below
big = abs( A[i][i] );
ibig = i;
for ( ii = i + 1; ii < size; ii++ )
{
temp = abs( A[ii][i] );
if ( temp > big)
{
big = temp;
ibig = ii;
}
}
if ( ibig != i )
{
for ( j = i; j < size; j++ ) swap( A[i][j],
A[ibig][j] );
swap( b[i], b[ibig] );
}

// Pivot
for ( ii = i + 1; ii < size; ii++ )
{
f = A[ii][i] / A[i][i];
for ( j = 0; j < size; j++ ) A[ii][j] -= f * A[i][j];
b[ii] -= f * b[i];
}
}

// Back-sub
for ( i = size - 1; i >= 0; i-- )
{
x[i] = b[i];
for ( j = i + 1; j < size; j++ ) x[i] -= A[i][j] * x[j];
x[i] /= A[i][i];
}

beam.V0 = x[0];
beam.dV0 = x[1];
for ( n = 0; n < nR; n++ )
{
i = n + 2;
react[n].R = x[i];

By: Harshit Rai


Page 19 of 23
}
}

//

void outp()
{
#define SP << setw( 15 ) <<

for ( int n = 0; n < pt.size(); n++ )


{
double x = pt[n].x;
pt[n].v = Defl( x );
pt[n].dvdx = Grad( x );
pt[n].S = SF ( x );
pt[n].M = BM ( x );
}

cout << "Beam:\n";


cout << " L: " << beam.L << '\n';
cout << " EI: " << beam.EI << '\n';
cout << '\n';

cout << "Point loads:\n" SP "x" SP "Value" << '\n';


for ( int i = 0; i < load.size(); i++ ) cout SP load[i].x
SP load[i].W << '\n';
cout << '\n';

cout << "Cont. loads:\n" SP "xl" SP "xr" SP "wl" SP "wr" <<


'\n';
for ( int i = 0; i < cont.size(); i++ ) cout SP cont[i].xl
SP cont[i].xr SP cont[i].wl SP cont[i].wr << '\n';
cout << '\n';

cout << "Reactions:\n" SP "x" SP "Type" SP "Value" << '\n';


for ( int i = 0; i < react.size(); i++ ) cout SP react[i].x
SP react[i].type SP react[i].R << '\n';
cout << '\n';

cout << "Monitors:\n" SP "Num" SP "x" SP "S" SP "M" SP


"slope" SP "down" << '\n';
for ( int i = 0; i < pt.size(); i++ )
cout SP i SP pt[i].x SP pt[i].S SP pt[i].M SP
pt[i].dvdx SP pt[i].v << '\n';
}

//

double Defl( double x )


{
double val = Vnr( x );

By: Harshit Rai


Page 20 of 23
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val += react[n].R * Mac( x,
react[n].x, 2 );
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 3 );
}
val += beam.dV0 * x + beam.V0;
return val / beam.EI;
}

//

double Grad( double x )


{
double val = dVnr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val += react[n].R * Mac( x,
react[n].x, 1 );
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 2 );
}
val += beam.dV0;
return val / beam.EI;
}

//

double BM( double x )


{
double val = Mnr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'M' ) val -= react[n].R * Mac( x,
react[n].x, 0 );
if ( react[n].type == 'F' ) val += react[n].R * Mac( x,
react[n].x, 1 );
}
return val;
}

//

double SF( double x )


{
double val = Snr( x );
for ( int n = 0; n < react.size(); n++ )
{
if ( react[n].type == 'F' ) val -= react[n].R * Mac( x,
react[n].x, 0 );

By: Harshit Rai


Page 21 of 23
}
return val;
}

//

double Vnr( double x )


{
return loadInt( x, 4 );
}

//

double dVnr( double x )


{
return loadInt( x, 3 );
}

//

double Mnr( double x )


{
return -loadInt( x, 2 );
}

//

double Snr( double x )


{
return loadInt( x, 1 );
}

//

double loadInt( double x, int p ) // pth integral of load


{
double val = 0.0;
for ( int n = 0; n < load.size(); n++ )
{
val += load[n].W * Mac( x, load[n].x, p - 1 );
}
for ( int n = 0; n < cont.size(); n++ )
{
val += cont[n].wl * ( Mac( x, cont[n].xl, p ) -
Mac( x, cont[n].xr, p ) );
val += cont[n].dwdx * ( Mac( x, cont[n].xl, p + 1 ) -
Mac( x, cont[n].xr, p + 1 ) - cont[n].dx * Mac( x, cont[n].xr,
p ) );
}
return val;
}

By: Harshit Rai


Page 22 of 23
//

double Mac( double x, double x0, int n ) // Macaulay bracket


& integrals
{
double xx = x - x0;

if ( xx < 0 ) return 0.0;


if ( n == 0 ) return 1.0;

double val = xx;


for ( int i = 2; i <= n; i++ ) val *= xx / i;
return val;
}

By: Harshit Rai


Page 23 of 23

You might also like