Вы находитесь на странице: 1из 3

Program for Assignment 1

C++ program
#include <iostream> #include <math.h> #include <stdlib.h> #include <cmath> #include <fstream> using namespace std; void gnuplot(const char *gnucommand) { char syscommand[1024]; sprintf(syscommand, "echo \"%s\" | gnuplot -persist", gnucommand); system(syscommand); } int main() { ofstream out("Assignment1.2.dat"); std::cout.precision(8); int i,j,node,L; double nu[4],c1,c3,k,dx,c[3],Rd[3]; node=100; L=1; dx=(double)L/(node-1); k=1000; //One parameter solution //Rd(L/3)=0 c[0]=k*2/(sqrt(3)*pow(M_PI,4)); //Rd(L/2)=0 c[1]=k/(pow(M_PI,4)); //Rd(L/5)=0 c[2]=k/(sin(M_PI/5)*(pow(M_PI,4))); //Two parameter solution c1=2/(sqrt(3)*pow(M_PI,4))*k; c3=0.00003289*k; for(i=0;i<node;i++) { nu[0]=c[0]*sin(M_PI*i*dx/L); nu[1]=c[1]*sin(M_PI*i*dx/L);

nu[2]=c[2]*sin(M_PI*i*dx/L); nu[3]=c1*sin(M_PI*i*dx/L)+c3*sin(3*M_PI*i*dx/L); //Here q0=1 Rd[0]=sin(M_PI*i*dx/L)*2/sqrt(3)-1; Rd[1]=sin(M_PI*i*dx/L)-1; Rd[2]=sin(M_PI*i*dx/L)/sin(M_PI/5)-1; out<<(i*dx)<<"\t"<<nu[0]<<"\t"<<nu[1]<<"\t"<<nu[2]<<"\t"<<nu[3]<<"\t"<<Rd[0]<<"\t "<<Rd[1]<<"\t"<<Rd[2]<<endl; } gnuplot("set terminal postscript eps size 4.5,2.62 enhanced color font 'Helvetica,10' lw 2;set output 'Assignment 1.1.eps';set border 31 linewidth .3 ;set title 'Simply supported beam deflection ' font 'Helvetica,13' ;set key ; set grid ; set pointsize .4 ;set xlabel 'Normalised axial location on the beam' font 'Helvetica,11' ;set yrange [0:18]; set ylabel 'Transverse deflection' font 'Helvetica,11';plot 'Assignment1.2.dat' using 1:2 title 'Rd(L/3) = 0' ,'Assignment1.2.dat' using 1:3 title 'Rd(L/2) = 0' ,'Assignment1.2.dat' using 1:4 title 'Rd(L/5) = 0'"); gnuplot("set terminal postscript eps size 4.5,2.62 enhanced color font 'Helvetica,10' lw 2;set output 'Assignment 1.2.eps';set border 31 linewidth .3 ;set title 'Residual Simply supported beam ' font 'Helvetica,13' ;set key ; set grid ; set pointsize .4 ;set xlabel 'Normalised axial location on the beam' font 'Helvetica,11' ; set ylabel 'Residual' font 'Helvetica,11';plot 'Assignment1.2.dat' using 1:6 title 'Rd(L/3) = 0','Assignment1.2.dat' using 1:7 title 'Rd(L/2) = 0' ,'Assignment1.2.dat' using 1:8 title 'Rd(L/5) = 0'"); gnuplot("set terminal postscript eps size 4.5,2.62 enhanced color font 'Helvetica,10' lw 2;set output 'Assignment 1.3.eps';set border 31 linewidth .3 ;set title 'Simply supported beam deflection - Two Parameter ' font 'Helvetica,13' ;set key ; set grid ; set pointsize .4 ;set xlabel 'Normalised axial location on the beam' font 'Helvetica,11' ;set yrange [0:14]; set ylabel 'Transverse deflection' font 'Helvetica,11';plot 'Assignment1.2.dat' using 1:5 title 'Two Term'"); out.close(); return 0; } Graphs

Вам также может понравиться