Updating Parameters in MATLAB COMSOL Using Loops Giving Different Results than normal COMSOL

18 views (last 30 days)
I am trying to change the parameters for my COMSOL program using loops in MATLAB. The parameters I wanted to change were set to be taken as parameters in the model function. Once I change the parameters I have the program find results of the simulation. My problem is that in MATLAB, the graphs of the results for the different parameter combinations were looking incorrect (see attached picture, blue center should be together). When I plugged the same parameters directly into the COMSOL program and ran the simulation in COMSOL the graphs were just fine (see attached, blue is in center as needed). This is strange to me because I downloaded "Compact History" version of the original COMSOL simulation to MATLAB and then updated the parameters as follows:
%convert values to string so we can use them in parameter updates
SIO2_str = num2str(SIO2_val);
Electrode_gap_str = num2str(Electrode_gap_val);
Electrode_height_str = num2str(Electrode_height_val);
%adding units
unit = '[um]';
SIO2_input = strcat(SIO2_str,unit);
Electrode_gap_input = strcat(Electrode_gap_str, unit);
Electrode_height_input = strcat(Electrode_height_str, unit);
model.param.set('Electrode_height', Electrode_height_input, 'height of electrode');%**
model.param.set('Electrode_gap', Electrode_gap_input, 'Gap between electrodes'); %**
model.param.set('Electrode_sidewall_height', SIO2_input);% ****
I even downloaded the "Compact History" for the simulation after directly entering the new parameters and it looked identical to the original "Compact History" code that I had updated with the exception of the parameter values. Any suggestions on how to fix this?

Accepted Answer

Johannes Hofmann
Johannes Hofmann on 20 Feb 2023
I had the same problem as you but with the calculation of modes and dispersion of optical fibers. The results obtained by matalb and comsol were different. In my case the problem was that num2str(value) was not precise and cutted the refractive index after 4 decimals. So I increased the precision num2str(val, precision) and everything was fine.
Maybe this might be helpful for someone in future.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!