#include #include "neural-nets-pde.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. */ // We are in the domain if phi > -EPS. #define EPS 1e-12 void Neural_Net_plot_with_maple(struct Neural_Net_PDE *nn, int n, int m, char *outfile) { double a = nn->bb_xrange[0]; double b = nn->bb_xrange[1]; double c = nn->bb_yrange[0]; double d = nn->bb_yrange[1]; FILE *fp; if ((fp = fopen(outfile, "w")) == NULL) { fprintf(stderr, "unable to open file `%s' for writing\n", outfile); return; } fprintf(fp, "plots:-display(MESH(["); for (int i = 0; i <= m; i++) { double y = c + (d-c)/m*i; fprintf(fp, "["); for (int j = 0; j <= m; j++) { double x = a + (b-a)/n*j; nn->phi_func(nn, x, y); if (nn->phi[0][0] > -EPS) { Neural_Net_eval(nn, x, y); double z = nn->phi[0][0]*nn->N[0][0]; fprintf(fp, "[%g,%g,%g],", x, y, z); } else { fprintf(fp, "[%g,%g,undefined],", x, y); } } fprintf(fp, "NULL],"); } fprintf(fp, "NULL]), labels=[x,y,z]);\n"); fclose(fp); }