// PROGRAM plot_function // plot analytical solution #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; // initial coffee temperature (C) (*Ts) = 22; // room temperature (C) printf("cooling constant r = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", r); // cooling constant printf("duration = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", tmax); // time (minutes) } void set_up_window(float xmin, float xmax, float ymin, float ymax) { float mx, my; mx = 0.01f*(xmax - xmin); // margin my = 0.01f*(ymax - ymin); GWindow(xmin - mx, ymin - my, xmax + mx, ymax + my); // default background color black on all computers except Macintosh GWmove2(xmin, ymin); // abbreviation for 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_; }