#include #include "neural-nets-ode.h" /* Writes a Maple script to plot the solution sampled at n+1 equally * spaced points x[0] = a, x[1], x[2], ..., x[n] on the interval [a,b]. * The distance between a pair consecutive points is (b-a)/n. * * If the script is named file.mpl, then execute it in Maple by * entering the command * read "/path/to/file.mpl"; * * Alternatively, copy and paste the contents of file.mpl into * a Maple worksheet. This latter option makes it possible to * edit the plotting command before executing it. */ void Neural_Net_plot_with_maple(struct Neural_Net_ODE *nn, int n, char *outfile) { double a = nn->a; double b = nn->b; FILE *fp; if ((fp = fopen(outfile, "w")) == NULL) { fprintf(stderr, "unable to open file `%s' for writing\n", outfile); return; } fprintf(fp, "plot(["); for (int i = 0; i <= n; i++) { double x = a + (b-a)/n*i; Neural_Net_phi(nn, x); Neural_Net_eval(nn, x); double y = nn->N[0] * nn->phi[0]; fprintf(fp, "[%g,%g],", x, y); } fprintf(fp, "NULL], title=\"hidden units = %d, training points = %d", nn->q, nn->nu); if (nn->exact_sol != NULL) fprintf(fp, "\\nerror vs exact = %g", Neural_Net_error_vs_exact(nn, n)); fprintf(fp, "\", color=\"Green\", labels=[x, u(x)], " "size=[600,300], font=[Times,bold,14]);\n"); fclose(fp); }