-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathPk Jha assignmnet
More file actions
274 lines (243 loc) · 4.52 KB
/
Pk Jha assignmnet
File metadata and controls
274 lines (243 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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<float> X;
for(int i=0;i<2*n;i++)
{
X.push_back(0);
}
vector<float> 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<float> U; // Getting the values of U
float temp;
cout<<"Enter the value of Overall Heat Transfer Coefficient";
for(int i=0;i<n;i++)
{
cin>>temp;
U.push_back(temp);
}
vector<float> 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<float> 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 "<<i<<"th effect";
cin>>X[i];
}
if((i>=n)&&(i<=2*n-1))
{
cout<<"Enter the liquid flowrates guess value of "<<i<<"th effect";
cin>>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<<J1[i][j]<<" ";
}
cout<<endl;
}
}