I need help with my code
    3 views (last 30 days)
  
       Show older comments
    
Here is the error I am getting:
Error using calculate_fluctuation_dissipation_factor
Too many input arguments.
Error in Fluctuational_electrodynamics_main (line 36)
  G = calculate_fluctuation_dissipation_factor(layer_properties(i), layer_properties(i+1), gap);
Below is the code I used:
% Define the material properties and temperatures of the layers
layer_properties = [...
    struct('conductivity', 0, 'n_fun', @(omega) refractive_index_real(omega, 1), 'k_fun', @(omega) refractive_index_imag(omega, 1), 'T', 400); % Layer 1 (top)
    struct('conductivity', 0, 'n_fun', @(omega) refractive_index_real(omega, 2), 'k_fun', @(omega) refractive_index_imag(omega, 2), 'T', 300); % Layer 2
    % Define the thicknesses of the layers
    layer_thicknesses = [500e-9, 1e-6]; % m
    % Define the distance between the multilayer stack and the reference surface
    d = 100e-9; % m rep. the distance between upper (emitter) and lower (PV cell)
    omega = linspace(0, 1e15, 1000); % rad/s
    % Calculate the heat transfer rate
    q = 0;
    for i = 1:length(layer_properties)-1
    % Calculate the fluctuation-dissipation factor
    gap = d + sum(layer_thicknesses(1:i));
    G = calculate_fluctuation_dissipation_factor(layer_properties(i), layer_properties(i+1), gap);
    % Calculate the temperature difference
    dT = layer_properties(i).T - layer_properties(i+1).T;
    % Add the contribution of this pair of layers to the total heat transfer rate
    q = q + G * dT^2;
    end
The first function defination
    function G = calculate_fluctuation_dissipation_factor(layer_properties, gap)
    % Define constants
    c = 3e8; % m/s
    h = 6.62607004e-34; % J.s
    k = 1.38064852e-23; % J/K
    % Define the frequency range
    omega = linspace(0, 1e15, 1000); % rad/s
    % Calculate the Bose-Einstein distribution function
    n1 = 1./(exp(h*omega./(k*layer_properties(1).T)) - 1);
    n2 = 1./(exp(h*omega./(k*layer_properties(2).T)) - 1);
    % Calculate the material's dielectric function
    epsilon1 = layer_properties(1).refractive_index^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
    epsilon2 = layer_properties(2).refractive_index^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
    % Calculate the reflection and transmission coefficients
    [R, T] = fresnel(epsilon1, epsilon2, omega, gap);
    % Calculate the fluctuation-dissipation factor
    G = (pi/6) * c * trapz((n1 + 1).*(n2 + 1).*(R + T).*epsilon1.*omega.^2);
    % Scale the fluctuation-dissipation factor by the distance between the surfaces
    G = G./gap^2;
    end
The second function
    function n = refractive_index_real(omega, layer_index)
    % Calculate the real part of the refractive index for a given layer as a
    % function of the angular frequency
    % Define the parameters for the refractive index function using lorentz
    % oscillator model
    parameters = [...
        % Layer 1
        struct('omega_0', 1e15, 'gamma', 8.9e11, 'n_inf', 6.7); % Layer 1 sic
        % Layer 2
        struct('omega_0', 1e15, 'gamma', 8.9e11, 'n_inf', 8.9e11); % Layer 2 sic
        % Layer 3
        %struct('omega_0', 3e15, 'gamma', 1e15, 'n_inf', 1.7); % Layer 3
        ];
    % Extract the parameters for the given layer
    omega_0 = parameters(layer_index).omega_0;
    gamma = parameters(layer_index).gamma;
    n_inf = parameters(layer_index).n_inf;
    % Calculate the real part of the refractive index
    n = n_inf - omega_0^2./(omega.^2 + 1i*gamma*omega);
0 Comments
Answers (2)
  Voss
      
      
 on 24 Dec 2022
        The function calculate_fluctuation_dissipation_factor takes two inputs, the first of which is a vector with (at least) two elements, as can be seen from the function definition:
function G = calculate_fluctuation_dissipation_factor(layer_properties, gap)
% ...
n1 = 1./(exp(h*omega./(k*layer_properties(1).T)) - 1);
n2 = 1./(exp(h*omega./(k*layer_properties(2).T)) - 1);
% ...
end
But you are calling the function with three inputs:
G = calculate_fluctuation_dissipation_factor(layer_properties(i), layer_properties(i+1), gap);
Instead, layer_properties(i) and layer_properties(i+1) should be together in a single vector, as the first input:
G = calculate_fluctuation_dissipation_factor(layer_properties([i i+1]), gap);
3 Comments
  Voss
      
      
 on 24 Dec 2022
				That error happens because layer_properties does not have a field called 'refractive_index_real'. (refractive_index_real is a function you have defined; it's not a field of layer_properties.)
layer_properties = [...
    struct('conductivity', 0, 'n_fun', @(omega) refractive_index_real(omega, 1), 'k_fun', @(omega) refractive_index_imag(omega, 1), 'T', 400); % Layer 1 (top)
    struct('conductivity', 0, 'n_fun', @(omega) refractive_index_real(omega, 2), 'k_fun', @(omega) refractive_index_imag(omega, 2), 'T', 300); % Layer 2
    ] % <- this seems to be missing in your code, by the way
As you can see, the fields of layer_properties are 'conductivity', 'n_fun', 'k_fun', and 'T'.
The code in your question refers to the field 'refractive_index' of layer_properties, which also doesn't exist.
% Calculate the material's dielectric function
epsilon1 = layer_properties(1).refractive_index^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
epsilon2 = layer_properties(2).refractive_index^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
Perhaps you mean:
epsilon1 = layer_properties(1).n_fun(omega).^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
epsilon2 = layer_properties(2).n_fun(omega).^2 - 0*omega*1i./(c*omega); % Non-conductive material, set conductivity to zero
?
  Byron Angulo
 on 24 Dec 2022
        G = calculate_fluctuation_dissipation_factor(layer_properties([i i+1]), gap);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

