Parameter Scan¶
With the parameterization of the test project in the previous section Keyword Substitution, it is straightforward to run a parameter scan within Matlab:
1%% holds computed scattering cross sections
2scattering_cross_section_scan = [];
3
4%% loop over radius values
5for radius = [0.3 : 0.005 : 0.5]
6 fprintf('\nSolving for radius %5.2e', radius);
7
8 % set current parameter and solve the project
9 keys.radius = radius;
10 results = jcmwave_solve('mie2D.jcmp', keys, 'logfile', 'null');
11
12 scs = real(results{2}.ElectromagneticFieldEnergyFlux{1});
13
14 % gather results
15 scattering_cross_section_scan(end+1, 1 : 2) = [radius, scs];
16end
17
18%% plot scattering cross section against rod radius
19radii = scattering_cross_section_scan(:, 1);
20scs = scattering_cross_section_scan(:, 2);
21plot(radii, scs, '-+', 'LineWidth', 2);
22xlabel('radius [\mu m]', 'FontSize', 14);
23ylabel('integral scattering cross section', 'FontSize', 14);
24set(gca, 'FontSize', 14);
In line 2 we initialize the matrix scattering_cross_section_scan which later holds the computed data. In line 5 we start a loop over the rod radius. In each step the key-value container keys is updated with the current radius value (line 9), followed by a solver call (line 10). The optional parameter logfile redirects the solver console output to a file (using null disregards all console output). In line 15 we gather the relevant data. Line 19-24 serve the plotting of the results, see Figure “Scattering Cross Section”.
Scattering Cross Section¶
Computed scattering cross section versus rod radius.
The next section Matlab Code Snippets demonstrates how to enrich the .jcmt input files with matlab scripts blocks.