diff --git a/Pk Jha assignmnet b/Pk Jha assignmnet new file mode 100644 index 0000000..2b6f7a7 --- /dev/null +++ b/Pk Jha assignmnet @@ -0,0 +1,274 @@ +int main() { + int n; + cout<<"Enter the value of n"; + cin>>n; + + N = 2*n; // Defining the value of N as the size of the Jacobian and other matrices + + vector X; + for(int i=0;i<2*n;i++) + { + X.push_back(0); + } + vector fx; + for(int i=0;i<2*n;i++) + { + fx.push_back(0); + } + float F,xf,Cp,lam,xp,tfeed,Ts; // Getting the values of feed and product from the user + + cout<<"Enter the value of feed"; + cin>>F; + cout<<"Enter the value of xfeed"; + cin>>xf; + cout<<"Enter the value of Cp"; + cin>>Cp; + cout<<"Enter the value of latent heat"; + cin>>lam; + cout<<"Enter the value of x product"; + cin>>xp; + cout<<"Enter the value of T feed"; + cin>>tfeed; + cout<<"Enter the value of temp of steam"; + cin>>Ts; + vector U; // Getting the values of U + float temp; + + cout<<"Enter the value of Overall Heat Transfer Coefficient"; + + for(int i=0;i>temp; + U.push_back(temp); + } + + vector T; // Vector of Tempuratures + + cout<<"Enter the Exit temperature of product"; + for(int i = 0; i < n-1; i++) + { + T.push_back(0); + } + + cin>>temp; + T.push_back(temp); + + + vector L; // Vector of liquid flowrates + + for(int i = 0; i < n-1; i++) + { + L.push_back(0); + } + + L.push_back(F*xf/xp); + + // guess array of x + for(int i=0;i<2*n;i++) + { + if(i==0) + { + cout<<"Enter the guess value of S"; + cin>>X[i]; + break; + } + + if(i==(2*n-1)) + { + cout<<"Enter the guess value of A"; + cin>>X[i]; + break; + } + if((i>0)&&(i<=n-1)) + { + cout<<"Enter the temp guess value of "<>X[i]; + } + if((i>=n)&&(i<=2*n-1)) + { + cout<<"Enter the liquid flowrates guess value of "<>X[i]; + } + } + + for(int i=0;i<2*n;i++) // Making the array of different functions from 1 to 2n + { + if(i==0) + { + fx[i]=F*Cp*(tfeed-T[0])+X[0]*lam-(F-X[n])*lam; + } + + if(i==n) + { + fx[i]=X[0]*lam-U[0]*X[2*n-1]*(Ts-X[1]); + } + + if((i>1)&&(i<=n-1)) + { + fx[i]=X[i+n-1]*Cp*(X[i]-X[i+1]) + (X[i+n-2]-X[i+n-1])*lam - (X[i+n-1]-X[n+i])*lam; + } + + if( i==1) + { + fx[i]=X[i+n-1]*Cp*(X[i]-X[i+1]) + (F-X[n])*lam - (X[n]-X[n+1])*lam; + } + + if( i == n+1) + { + fx[i] = (F - X[n])*lam - U[1]*X[2*n-1]*(Ts - X[1]); + } + + if((i > n+1) && ( i<=2*n-1)) + { + fx[i] = ( X[i-2] - X[i-1])*lam - U[i-n]*X[2*n-1]*(X[i-n] - X[i-n+1]); + } + } + + // Defining the jacobian vector and initiallizing it + float J[2*n][2*n]; + + int count = 0; + int count1=0; + float flowrate[n+1]; + flowrate[0] = F; + for( int i = 1; i < n+1; i++) + { + flowrate[i] = L[i-1]; + } + + for(int i = 0; i < 2*n; i++) + { + if( i == 0) + { + + for(int j = 0; j < 2*n; j++) + { + if( j == 0 || j == n) + { + J[j][i] = lam; + } + else + { + J[j][i] = 0.0; + } + } + } + + if( i > 0 && i < n) + { + count = 0; + for(int j = 0; j < n; j++) // Temperature above + { + if( j >= i-1 && j <= i) + { + J[j][i] = Cp * flowrate[j] * pow(-1,i+j); + } + else + { + J[j][i] = 0; + } + } + + for(int j = n; j < 2*n; j++) // Temperature Below + { + if( j >= i-1+n && j <= i+n) + { + J[j][i] = X[2*n-1] * U[j-n] * pow(-1,i+j+1); + } + else + { + J[j][i] = 0; + } + } + } + if( i >=n && i < 2*n-2) + { + count = 0; + for(int j = 0; j < n; j++) // Temperature above + { + if( j >= i-n && j <= i-n+2) + { + if(j==(i-n+1)) + { + J[j][i]=Cp*(T[i-n]-T[i-n+1])-2*lam; + } + else + { + J[j][i] = lam; + } + } + else + { + J[j][i] = 0; + } + } + + for(int j = n; j < 2*n; j++) // Temperature Below + { + if( j == i+1 ) + { + J[j][i] = -lam; + } + else if ( j == i+2) + { + J[j][i] = lam; + } + else + { + J[j][i] = 0; + } + } + } + + + if( i == 2*n-2) + { + count = 0; + for(int j = 0; j < n; j++) // Temperature above + { + if( j >= i-n && j <= i-n+1) + { + if(j==(i-n+1)) + { + J[j][i]=Cp*(T[i-n]-T[i-n+1])-2*lam; + } + else + { + J[j][i] = lam; + } + } + else + { + J[j][i] = 0; + } + } + + for(int j = n; j < 2*n; j++) // Temperature Below + { + if( j == i+1 ) + { + J[j][i] = -lam; + } + else if ( j == i+2) + { + J[j][i] = lam; + } + else + { + J[j][i] = 0; + } + } + } + } + + float J1[N][N]; // Defining the inverse of the matrix J + inverse(J, J1); + for(int i = 0; i < N; i++) + { + for(int j = 0; j < N; j++) + { + cout<