// PROGRAM plot_function // 解析解をプロットする #include "TrueBASIC.h" int main(); void initial(double *t, double *tmax, double *r, double *Ts, double *T0); void set_up_window(float xmin, float xmax, float ymin, float ymax); void show_plot(double *t, double tmax, double r, double Ts, double T0); double f(double t, double r, double Ts, double T0); int main() { double T0, Ts, r, t, tmax; GWopen(0); initial(&t, &tmax, &r, &Ts, &T0); set_up_window((float)t, (float)tmax, (float)Ts, (float)T0); show_plot(&t, tmax, r, Ts, T0); GWquit(); return 0; } void initial(double *t, double *tmax, double *r, double *Ts, double *T0) { char Stmp1_[_LBUFF_]; (*t) = 0; (*T0) = 83; // コーヒーの初期温度(C) (*Ts) = 22; // 室温(C) printf("cooling constant r = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", r); // 冷却定数 printf("duration = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", tmax); // 時間(分) } void set_up_window(float xmin, float xmax, float ymin, float ymax) { float mx, my; mx = 0.01f*(xmax - xmin); // マージン my = 0.01f*(ymax - ymin); GWindow(xmin - mx, ymin - my, xmax + mx, ymax + my); // Macintosh を除いたすべての計算機の背景色の既定値は黒である GWmove2(xmin, ymin); // PLOT LINES: 文の省略形 GWline2(xmax, ymin); GWline2(xmin, ymin); GWline2(xmin, ymax); } void show_plot(double *t, double tmax, double r, double Ts, double T0) { GWsetpen(-1, -1, -1, -1); GWsetpen(RED, -1, -1, -1); while((*t) <= tmax) { GWline2((float)((*t)), (float)(f(*t, r, Ts, T0))); (*t) += 0.1; } } double f(double t, double r, double Ts, double T0) { double f_; f_ = Ts - (Ts - T0)*exp(-r*t); return f_; }