作者wodada (wodada)
看板C_and_CPP
標題[問題] 請各路英雄好漢來幫我個忙
時間Fri Apr 23 01:38:37 2010
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
老師希望我們用迭代的方法來算出數值,雖然執行了出來,但數字卻沒有顯示.....
設定一個Q1,接著算出其他如速度,雷諾係數,水頭損失等數值....,再與由
算出來的數值(如速度等)與推算出來的數值做比較,當誤差大於0.001時則繼續算
但因為輸入的Q1是猜測的,所以要反推後來真正Q1,Q2,Q3的數值
希望得到的正確結果:
後面的字串有正確數值出來.....
Guess Q1 :
2.889
the velocity in pipe one is: 0.000000
the reynold number is:
the friction is:
the head loss one is:
the multipul friction and velocity 2 is:
Guess V2:
the velocity in pipe 2 is:
the flow rate of 2 is:
f3 * V3 * V3:
Guess V3:
the velocity 3 is:
the flow rate 3 is:
the Q1 is:
the Q2 is:
the Q3 is:
the V1 is:
the reynold number is:
the friction 1 is:
the head loss 1 is:
the V2 is:
the Rn is:
the f2 is:
the head loss 2 is:
the V3 is:
the Rn is:
the f3 is:
the head loss 3 is:
the pressure B is:
the Ws is:
請按任意鍵繼續 . . .
程式跑出來的錯誤結果:
可以執行,但卻無輸出結果....
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
DEV-C++
有問題的code: (請善用置底文標色功能)
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
float PA, testQ2, testQ3, rn, Rn, Q1, Q2, Q3, error;
float QA= 5.3;
float ZA= 100.0;
float ZB= 80.0;
// double A1= 3.1415 /4.0;
// double A2= 3.1415 * (0.67 * 0.67)/4.0;
// double QA= 5.3;
// constant double A3= A2;
double shipe_Rn(double V, double Dia)
{
return V * Dia / (0.00193 / 64.348);
}
double shipe_f(double rn, double E, double Dia)
{
double i = log10(6.9 / rn + pow( E / (3.7 * Dia), 1.11));
return 0.3086 / (i * i);
}
double shipe_h(double f, double L, double Dia, double V)
{
return f * L / Dia * V * V / (2 * 32.174);
}
double shipe_error(double A, double B)
{
return (A - B) / A;
}
double shipe_Q1(double Q)
{
double Q11 = Q;
double error = 1000.0;
double final_hf1 = 0.0;
while (error >= 0.001) {
double V1 = Q11 / (3.1415/4.0);
printf("the velocity in pipe one is: %f \n", V1);
double rn = shipe_Rn(V1, 1);
printf("the reynold number is: \n", Rn);
double f1 = shipe_f(rn, 0.001, 1);
printf("the friction is: \n", f1); ;
double hf1 = shipe_h(f1, 3000, 1, V1);
printf("the head loss one is: \n", hf1);
double hf2 = hf1;
double point = hf2 / 3000 * 0.67 * 2 * 32.174;
printf("the multipul friction and velocity 2 is: \n", point);
printf("Guess V2:\n");
double V2;
scanf("the %f is:\n", &V2);
error = 1000.0;
double f2 = 0.0;
double V22 = 0.0;
while (error >= 0.001) {
f2 = point / (V2 * V2);
V22 = sqrt(hf2 / f2 / 3000 * 0.67 * 2 * 32.174);
error = shipe_error(V2, V22);
V2 = V22;
}
printf("the velocity in pipe 2 is: \n", V2);
double Q22 = V2 * (3.1415 * (0.67 * 0.67)/4.0);
printf("the flow rate of 2 is: \n", Q2);
double hf3 = hf1;
point = hf3 / 3000 * 0.67 * 2 * 32.174;
printf("f3 * V3 * V3: \n", point);
printf("Guess V3:\n");
double V3;
scanf("input the %f:\n", &V3);
error = 1000.0;
double f3 = 0.0;
double V33 = 0.0;
while (error >= 0.001) {
f3 = point / (V3 * V3);
V33 = sqrt(hf3 / f3 / 3000 * 0.67 * 2 * 32.174);
error = shipe_error(V3, V33);
V3 = V33;
}
printf("the velocity 3 is: \n", V3);
double Q33 = V3 * (3.1415 * (0.67 * 0.67)/4.0);
printf("the flow rate 3 is: \n", Q3);
double Q1 = (Q11 / (Q11 + Q22 + Q33)) * QA;
double Q2 = (Q22 / (Q11 + Q22 + Q33)) * QA;
double Q3 = (Q33 / (Q11 + Q22 + Q33)) * QA;
printf("the Q1 is: \n", Q1);
printf("the Q2 is: \n", Q2);
printf("the Q3 is: \n", Q3);
Q11 = Q1;
V1 = Q11 / (3.1415/4.0);
printf("the V1 is: \n", V1);
rn = shipe_Rn(V1, 1);
printf("the reynold number is: \n", Rn);
f1 = shipe_f(rn, 0.001, 1);
printf("the friction 1 is: \n", f1);
final_hf1 = shipe_h(f1, 3000, 1, V1);
error = shipe_error(hf1, final_hf1);
Q11 = Q1;
testQ2 = Q2;
testQ3 = Q3;
}
return final_hf1;
}
double shipe_hf2(double Q)
{
double Q22 = Q;
double V2 = Q22 / (3.1415 * (0.67 * 0.67)/4.0) ;
printf("the V2 is: \n", V2);
double red = shipe_Rn(V2, 0.67);
printf("the Rn is: \n", Rn);
double f2 = shipe_f(red, 0.0001, 0.67);
printf("the f2 is: \n", f2);
double hf2 = shipe_h(f2, 3000, 0.67, V2);
return hf2;
}
double shipe_hf3(double Q)
{
double Q33 = Q;
double V3 = Q33 / (3.1415 * (0.67 * 0.67)/4.0);
printf("the V3 is: \n", V3);
double red = shipe_Rn(V3, 0.67);
printf("the Rn is: \n", Rn);
double f3 = shipe_f(rn, 0.0001, 0.67);
printf("the f3 is: \n", f3);
double hf3 = shipe_h(f3, 3000, 0.67, V3);
return hf3;
}
int main()
{
double Q;
printf("Guess Q1 : \n", Q1);
scanf("please input the flow rate:\n", &Q);
double hf1 = shipe_Q1(Q);
printf("the head loss 1 is: \n", hf1);
double hf2 = shipe_hf2(testQ2);
printf("the head loss 2 is: \n", hf2);
double hf3 = shipe_hf3(testQ3);
printf("the head loss 3 is: \n", hf3);
double hf = (hf1 + hf2 + hf3) / 3;
double PB = 64.348 * (ZA - ZB) - hf + PA;
printf("the pressure B is: \n", PB);
double Ws = (ZA - ZB) - hf;
printf("the Ws is: \n", Ws);
system("pause");
}
補充說明:
本人曾在printf()中加入%f,可是所造成的數字卻是0.0000000或亂碼
另外,一開始輸入的Q1為自己假設的數值,請各位幫忙.....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.47.172.69
→ james732:1.改個有意義的標題 2.請善用debugger 04/23 01:40
推 loveme00835:double 要用%lf印 04/23 01:41