Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
AND COMPUTER
PROGRAMMING
111610145 SHAHBAZ ANIS SHOLAPURE
111610141 MAYANK PATIL
111610142 BUDDHAGOSH RAGADE
111610148 ROHAN THORAT
T.Y BTECH MECHANICAL DIVISION 2
BATCH G
Page |1
TUTORIAL 4
CODE:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
// Use of file function to create a file by name ANS.TXT
FILE *fp;
fp = fopen("tp.txt","w");
//For loop to print the table
double arr1[8] = {0.5,2,3,4,6,8,10,11};
double arr2[8] =
{336,294.4,266.4,260.8,260.5,249.6,193.6,165.6};
Page |2
OUTPUT:
Pressure(kPa) Volume(m^3)
336.000000 0.500000
294.400000 2.000000
266.400000 3.000000
260.800000 4.000000
260.500000 6.000000
249.600000 8.000000
193.600000 10.000000
165.600000 11.000000
Area under the curve between 1st and 2nd point = 472.800000 kJ.
Area under the curve between 2nd and 4th point = 540.266667 kJ.
Area under the curve between 4th and 7th point = 1488.525000
kJ.
Area under the curve between 7th and 8th point = 179.600000 kJ.
The total work done by the gas is equal to 2681.191667 kJ
Page |5
CODE:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define f(x) (x*pow(exp(1),(2*x))) //given function
#define av 504.5359 //analytical value
#define h(x) ((2.25+2.25*x)*(pow(exp(1),(3+3*x)))) //varaible changed
according to limits
int main()
{
float I,c0,c1,c2,c3,x1,x2,x3,x0,err;
c0=1,c1=1,x0=-0.577350269,x1=0.577350269;
I=c0*h(x0)+c1*h(x1);
printf("\nValue of integral using two point Gauss Legendre formula
is:%f",I);
err=((av-I)/av)*100;
Page |6
OUTPUT:
Value of integral using two point Gauss Legendre formula is:406.295044
Value of error using two point Gauss Legendre formula is:19.471529 %
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i,j,x,h,t;
float vel1, vel2, vel3, acc1, acc2, acc3;
float arr[2][9]={0,2,4,6,8,10,12,14,16,0,0.7,1.8,3.4,5.1,6.3,7.3,8.0,8.4};
printf("Enter the time in sec \n");
scanf("%d",&t); //Taking the time from the user//
for(i=0;i<8;i++)
{
if(t==arr[0][i])
{
x=i;
exit;
} //Finding the position of time in the array//
}
printf("The position of the time in the array is %d \n", x);
h=(arr[0][2]-arr[0][1]); //Finding the value of h//
printf("The value of h is %d \n", h);
Page |9
OUTPUT:
Enter the time in sec
10
The position of the time in the array is 5
The value of h is 2
The velocity at t=10sec by centered finite difference is 0.541667
The acceleration at t=10sec by centered finite difference is -0.041667
The velocity at t=10sec by forward finite difference is 0.575000
The acceleration at t=10sec by forward finite difference is -0.075000
The velocity at t=10sec by backward finite difference is 0.475001
The acceleration at t=10sec by backward finite difference is -0.275000