#include #include "neural-nets-pde.h" // names of matlab's plotting variables #define XVEC "PLOT_WITH_MATLAB_FD_XVEC" #define YVEC "PLOT_WITH_MATLAB_FD_YVEC" #define ZMAT "PLOT_WITH_MATLAB_FD_ZMAT" #define EPS 1e-12 // We are in the domain if phi > -EPS. void Neural_Net_plot_with_matlab(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, "%s = [\n", XVEC); for (int i = 0; i <= n; i++) { double x = a + (b-a)/n*i; fprintf(fp, "%g ", x); } fprintf(fp, "\n];\n"); fprintf(fp, "%s = [\n", YVEC); for (int j = 0; j <= m; j++) { double y = c + (d-c)/m*j; fprintf(fp, "%g ", y); } fprintf(fp, "\n];\n"); fprintf(fp, "%s = [\n", ZMAT); for (int i = 0; i <= m; i++) { double y = c + (d-c)/m*i; for (int j = 0; j <= n; 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 ", z); } else { fprintf(fp, "NaN "); } } fprintf(fp, "\n"); } fprintf(fp, "];\n"); fprintf(fp, "surf(%s, %s, %s)\n", XVEC, YVEC, ZMAT); fprintf(fp, "xlabel('x')\n"); fprintf(fp, "ylabel('y')\n"); fprintf(fp, "zlabel('u')\n"); fprintf(fp, "colormap jet\n"); fclose(fp); }