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
|
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
int main () {
double Material1=0.00001, SpatialPoint=0, Tside, Tinitial, L, time;
double const PI = acos(-1);
double x1=0.0025, x2=0;
double Sum1 = 0.0, Sum2 = 0.0, T1 = 0.0, T2 = 0.0, CoolingOff1, CoolingOff2;
int n;
double Temp1Series, Temp2Series;
char again = 'Y';
{ cout << " This program computes the change in temperature after a given time interval, at a given location and at a specified board thickness. " << endl;
}
while (again == 'y' || again == 'Y')
{
//Get users values
cout << "Please enter your T side value. " << "Enter a number between 20 and 25: ";
cin >> Tside;
while (Tside < 20 || Tside > 25)
{
cout << "Error ! Enter number again !: ";
cin >> Tside;
}
cout << "Please enter your T initial value. " << "Enter a number between 50 and 100: ";
cin >> Tinitial;
while (Tinitial < 50 || Tinitial > 100)
{
cout << "Error ! Enter number again !: ";
cin >> Tinitial;
}
cout << "Please enter the thickness of the circuit board (L). " << "Enter a number between 0.005 and 0.008: ";
cin >> L;
while (L < 0.005 || L > 0.008)
{
cout << "Error ! Enter number again !: ";
cin >> L;
}
cout << "Please enter the time after which you want to check the temperature. " << "Enter a number between 1 and 50: ";
cin >> time;
while (time < 1 || time > 50)
{
cout << "Error ! Enter number again!: ";
cin >> time;
}
cout << "Pi = " << PI << endl;
cout << "Please enter the number of your type of material. " << "M1 = 0.00001, M2 = 0.00004 or M3 = 0.000006?: " << endl;
cin >> Material1;
cout << "Please enter 'x' the spatial point at which you want to check your temperature. Divide what you picked for L by 2. " << endl;
cin >> x1;
x2 = 0;
SpatialPoint = L/2;
// Compute the sum of the series
for(n=1; n <= 100; n++)
{
Temp1Series = exp((-(n*PI)*(n*PI))*(Material1*time)/(L*L))*((1.0-cos(n*PI))/(n*PI))*sin((n*PI*x1)/L);
Temp2Series = exp((-(n*PI)*(n*PI))*(Material1*time)/(L*L))*((1.0-cos(n*PI))/(n*PI))*sin((n*PI*x2)/L);
cout << "Temp1Series = " << Temp1Series << endl;
cout << "Temp2Series = " << Temp2Series << endl;
Sum1 = Sum1 + Temp1Series;
Sum2 = Sum2 + Temp2Series;
T1 = Tside + ((2*(Tinitial - Tside))*(Sum1));
T2 = Tside + ((2*(Tinitial - Tside))*(Sum2));
}
cout << "Sum T(L/2,t) = " << Sum1 << endl;
cout << "Sum T(0,t) = " << Sum2 << endl;
cout << "The final temperature T(L/2,t) = " << T1 << endl;
cout << "The final temperature T(0,t) = " << T2 << endl;
CoolingOff1 = (T1 - Tside)/(Tinitial-Tside);
CoolingOff2 = 0.735*(x1/L)*exp(-time);
if (CoolingOff1>CoolingOff2) {
cout << "Sorry, the chosen parameters have not met the specifications. Please choose new ones";
} else if(CoolingOff1<=CoolingOff2) {
cout << "Great ! The chosen parameters have met the specifications ! ";
}
{
cout << "Would you like to perform another computation? (y/n) " ;
cin >> again;
}
}
cout << "Have a great day ! Goodbye." << endl;
return 0;
}
| |