c_c++pgms

6
1. Program for RK- IV order differential equation #include <stdio.h> #include <math.h> #define N 2 /* number of first order equations */ #define dist 0.1 /* stepsize in t*/ #define MAX 50.0 /* max for t */  FILE *output; /* internal filename */ main() { double t, y[N]; int j; voi d runge4( dou bl e x, doubl e y[ ], dou bl e st ep) ; /* Runge- Kutt a fu ncti on */ double f(double x, double y[], int i); /* function for derivatives */ output=fopen("osc.dat", "w"); /* external filename */ y[0]=1.0; /* initial position */ y[1]=0.0; /* initial velocity */ fprintf(output, "0\t%f\n", y[0]);  for (j=1; j*dist<=MAX ;j++) /* time loop */ { t =j*dist; runge4(t, y, dist); fprintf(output, "%f\t%f\n", t, y[0]); } fclose(output); } double f(double x, double y[], int i) { if (i==0) return(y[1]); /* derivative of first equation */ if (i ==1) return(- 0. 2*y[ 1] -y [0]) ; /* der ivat ive of s econd eq uati on */ } void runge4(double x, double y[], double step) { double h=step/2.0, /* the midpoint */ t1[N], t2[N], t3[N], /* temporary storage arrays */ k1[N], k2[N], k3[N],k4[N]; /* for Runge-Kutta */ int i; for (i=0;i<N;i++) t1[i]=y[i]+0.5*(k1[i]=s tep*f(x, y, i)); for (i=0;i<N;i++) t2[i]=y[i]+0.5*(k2[i]=s tep*f(x+h, t1, i)); for (i=0;i<N;i++) t3[i]=y[ i]+ (k3[i] =s te p*f (x+h, t2, i) ); for (i=0;i<N;i++) k4[i]=step*f(x+step, t3, i); for (i=0;i<N;i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/ 6.0; } 2. Runge-Kutta II Order Solution to the nearest approximation for the problem #include<stdio.h> #include<conio.h>

Upload: raazia-mir

Post on 07-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 1/6

1. Program for RK- IV order differential equation

#include <stdio.h>

#include <math.h>#define N 2 /* number of first order equations */

#define dist 0.1 /* stepsize in t*/

#define MAX 50.0 /* max for t */ 

FILE *output; /* internal filename */

main(){

double t, y[N];

int j;void runge4(double x, double y[], double step); /* Runge-Kutta function */

double f(double x, double y[], int i); /* function for derivatives */

output=fopen("osc.dat", "w"); /* external filename */y[0]=1.0; /* initial position */

y[1]=0.0; /* initial velocity */

fprintf(output, "0\t%f\n", y[0]);

 for (j=1; j*dist<=MAX ;j++) /* time loop */

{

t =j*dist;runge4(t, y, dist);

fprintf(output, "%f\t%f\n", t, y[0]);

}fclose(output);

}

double f(double x, double y[], int i){

if (i==0) return(y[1]); /* derivative of first equation */if (i==1) return(-0.2*y[1]-y[0]); /* derivative of second equation */

}void runge4(double x, double y[], double step)

{

double h=step/2.0, /* the midpoint */t1[N], t2[N], t3[N], /* temporary storage arrays */

k1[N], k2[N], k3[N],k4[N]; /* for Runge-Kutta */

int i;for (i=0;i<N;i++) t1[i]=y[i]+0.5*(k1[i]=step*f(x, y, i));

for (i=0;i<N;i++) t2[i]=y[i]+0.5*(k2[i]=step*f(x+h, t1, i));

for (i=0;i<N;i++) t3[i]=y[i]+ (k3[i]=step*f(x+h, t2, i));for (i=0;i<N;i++) k4[i]=step*f(x+step, t3, i);for (i=0;i<N;i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;

}

2. Runge-Kutta II Order Solution to the nearest approximation for the problem

#include<stdio.h>#include<conio.h>

Page 2: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 2/6

Page 3: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 3/6

#include<conio.h>#include<math.h>

void main()

{float biom1, biom2, sub1, sub2, time, mu,tdouble,yield;

clrscr();

printf("Pgm for finding Sp. Gr. Rate, Doubling Time & Yield Coefficient.");printf("\nEnter the initial and final biomass concn (g/l).\n\n");

scanf("%f%f",&biom1,&biom2);

printf("\nEnter the initial and final substrate concn (g/l).\n\n");

scanf("%f%f", &sub1,&sub2);printf("\nEnter the time period of fermentation (min).\n\n");

scanf("%f", &time);

mu = log(biom2/biom1)/time;tdouble = log(2)/mu;

yield = (biom2 - biom1)/(sub1 - sub2);

printf("\nSp. Gr. Rate = %f/ min.\n",mu);printf("\nDoubling Time = %f min.\n", tdouble);

printf("\nYield Coefficient = %f\n", yield);

getch();

}

PROGRAM TO FIND THE OPTIMUM TEMPERATURE AND PH FOR MAXIMUM ENZYME

ACTIVITY

#include<iostream.h>

#include<stdio.h>#include<conio.h>

class enzyme{

 public:float Var[50], Act[50];

int n; public:

void SetArrayLength(int x);

void ArrayInput();int CompareData();

};

void enzyme::SetArrayLength(int x)

{

n = x;}

void enzyme::ArrayInput()

{for (int i= 0; i < n; i++) cin>> Var[i] >>Act[i];

}

Page 4: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 4/6

int enzyme::CompareData()

{

int j; float big;big = Act[0]; j = 0;

for (int k = 0; k < n; k++)

if (Act[k] > big){

big = Act[k];

j = k;

}return(j);

}

PROGRAM TO FIND THE OPTIMUM TEMPERATURE AND PH FOR MAXIMUM ENZYME

ACTIVITY

void main()

{

enzyme E1,E2;

int len,p1, p2;clrscr();

cout<<"Program to find the Optimum Temperature and pH for maximum enzyme activity\n";

cout<<"\nEnter the no. of Temperature - Activity datasets.\n\n";cin>>len;

E1.SetArrayLength(len);

cout<<"\n\nEnter the Temperature & coresponding Activity data one by one.\n\n";E1.ArrayInput();

cout<<"\n\nEnter the no. of pH - Activity datasets.\n\n";

cin>>len;E2.SetArrayLength(len);

cout<<"Enter the pH & coresponding Activity data one by one.\n\n";E2.ArrayInput();

p1 = E1.CompareData();p2 = E2.CompareData();

cout<<"Opt. Temperature is "<<E1.Var[p1]<<" which corresponds to a max. activity of 

"<<E1.Act[p1]<<".\n";cout<<"\n\nOpt. pH is "<<E2.Var[p2]<<" which corresponds to a max. activity of 

"<<E2.Act[p2]<<".\n";

getch();}

C++ PROGRAM TO DERVIE THE COLUMN HEIGHT NEEDED TO ACIEVE THESPECIFIED DEGREE OF CONVERSION IN A FLUIDIZED BED REACTOR 

#include<iostream.h>

#include<conio.h>class degree

{

public:void colht();

Page 5: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 5/6

private:float m,rm,l,a,f,k,s,h,v;

};

void degree::colht(){

v=((m*rm*l*a)/(f*k*s))*h;

}void main()

{

float m,rm,l,a,f,k,s,h,v;

clrscr();degree d;

cout<<”Enter the values of m,rm,l,a,f,k,s,h \n”;

cin>> m>>rm>>l>>a>>f>>k>>s>>h;d.colht();

cout<<”v= “<<v;

getch();}

Output:

Enter the values of vm,km,k1,h,s

1.0 2.0 3.0 4.0 1.0 2.0 3.0 7.0

v=28.0

C++ PROGRAM TO FIND THE OPTIMUM PH AND TEMPERATURE FOR MAXIMUM

ENZYME ACTIVITY

#include<iostream.h>

#include<conio.h>class optimum

{public:

void phtemp();private:

float vm,s,km,k1,h,v;

};void optimum::phtemp()

{

float v;v=vm*s*(km*(1+(k1/h)))+s;

}

void main(){

float vm,s,km,k1,h,v;

optimum o; /*creating the object using the class name*/

cout<<”Enter the values of vm,km,k1,h,s\n”;cin>>vm>>km>>k1>>h>>s;

o.phtemp(); /*calling the fn using the object*/

cout<<”v= “<<v;getch();

Page 6: C_C++pgms

8/6/2019 C_C++pgms

http://slidepdf.com/reader/full/ccpgms 6/6

}

Output:

Enter the values of vm,km,k1,h,s

1.1 2.1 3.1 4.2 5.2

v=-4.844e-29

C++ PROGRAM TO FIND THE OPTIMUM RATE FOR MAXIMUM CELL PRODUCTIVITY

#include<iostream.h>#include<conio.h>

class cell

{public:

void prod();

private:float u,s,ks,d;

};

void cell::prod()

{d=(u*s)/(ks+s);

}

void main(){

float u,s,ks,d;

clrscr();cell c;

cout<<”Enter the values of u,s,ks \n”;

cin>> u>>s>>ks;c.prod();

cout<<”d= “<<d;getch();

}

Output:

Enter the values of u,s,ks

1.2 2.3 3.4

d=16.6249