Error: get_steady​_state>@(x​)equilibri​um(x,Wl,Pi​n,T0) (第 41 行) 输入参数太多。Error Code Location : [a_steady, ~, exitflag, ~] = fsolve(@(x) equilibrium(x, Wl, Pin, T0), [real(a_steady)*1e16 imag(a_steady)*1e16], opt);

function [y0, deltaW0, success] = get_steady_state(Wl, Pin, T0, Vbias, init_guess)
% Gets the steady state solution for the system of nonlinear equations
% Inputs
% ------
% % Wl --> Laser frequency (rad/s)
% Pin --> Input power (W)
% T0 --> Ambient temperature (K)
% Vbias --> Bias voltage (V)
% init_guess (optional) --> If specified, uses init_guess as the
% initial guess for the solution of the nonlinear system
c = 2.997e8;
hbar = 1.05e-34;
if nargin == 5 && ~ logical(sum((isnan(init_guess))))
a_steady = init_guess;
else
[gamma_0, gamma_lin, gamma_rad, kappa, ... % loss params
Vring, V_TPA, V_FCA, gamma_disk, gamma_FCA, gamma_TPA, ... % Optical mode volumes and confinements
gamma_th, rho_Si, Cp_Si, dnSidT, ... % Thermal related stuff, instantaneous value at T+deltaT
gamma_th_eq, Cp_Si_eq, dnSidT_eq, ... % Thermal related stuff, equivalent value (see comments in code)
gamma_r, alfa_p, alfa_n, dnSidNn, dnSidNp, ... % Carrier related stuff
beta_Si, n_Si, ng, ... % Silicon related parameters
Wl, W0, deltaW0_cold, ... % Ring related stuff
dW0dV, tau] ... % Electro-optic driving related stuff
= ring_params(Wl, T0, 0, 0, 0);
a_steady = 1i*kappa*sqrt(Pin)/((gamma_rad + gamma_0 + gamma_lin)/2+1i*deltaW0_cold); % Initial guess for the solver
% a_steady = [0, 0];
if deltaW0_cold == 0
Wl = Wl + 1e12;
end
end
% Solve the trascendental equation
opt = optimoptions('fsolve', 'TolFun', 1e-10, 'StepTolerance', 1e-12, 'Display', 'off');
[a_steady, ~, exitflag, ~] = fsolve(@(x) equilibrium(x, Wl, Pin, T0), [real(a_steady)*1e16 imag(a_steady)*1e16], opt);
a_steady = a_steady*1e-16;
% Refine the solution iteratively to be self consistent with
% deltaT.
deltaT = 0;
prev_sol = Inf;
num_counts = 0;
while abs(deltaT-prev_sol) > 0.5 && num_counts < 100
prev_sol = deltaT;
[gamma_0, gamma_lin, gamma_rad, kappa, ... % loss params
Vring, V_TPA, V_FCA, gamma_disk, gamma_FCA, gamma_TPA, ... % Optical mode volumes and confinements
gamma_th, rho_Si, Cp_Si, dnSidT, ... % Thermal related stuff, instantaneous value at T+deltaT
gamma_th_eq, Cp_Si_eq, dnSidT_eq, ... % Thermal related stuff, equivalent value (see comments in code)
gamma_r, alfa_p, alfa_n, dnSidNn, dnSidNp, ... % Carrier related stuff
beta_Si, n_Si, ng, ... % Silicon related parameters
Wl, W0, deltaW0_cold, ... % Ring related stuff
dW0dV, tau] ... % Electro-optic driving related stuff
= ring_params(Wl, T0, deltaT, 0, 0);
% This is an equilibrium calcualtion, so we care about thermal
% equivalent values
H = (gamma_FCA*beta_Si*c^2)/(2*hbar*(Wl)*ng^2*V_FCA^2*gamma_r);
G = (gamma_disk/(rho_Si*Cp_Si_eq*Vring*gamma_th_eq));
E = (gamma_TPA*beta_Si*c^2/(V_TPA*ng^2));
F = (alfa_p+alfa_n)*c*H/ng;
a_re = a_steady(1);
a_im = a_steady(2);
u = a_re.^2 + a_im.^2;
deltaT = G*(gamma_lin + E*u + F*u^2)*u;
%abs(deltaT-prev_sol)
num_counts = num_counts+1;
end
Ntpa_steady = H*u^2;
deltaT_steady = G*(gamma_lin + E*u + F*u^2)*u;
deltaW0 = deltaW0_cold - (-W0/n_Si)*(dnSidT_eq*G*(gamma_lin+E*u+F*u^2)*u ...
+ dnSidNn*(H*u^2*1e-6)^1.05 + dnSidNp*(H*u^2*1e-6)^0.8);
% Detuning between laser wavelenght and resonance wavelength =
% = Wl - W0
y0 = [a_steady(1), a_steady(2), deltaT_steady, Ntpa_steady, Vbias];
if exitflag < 1
success = 0;
else
success = 1;
end
%s_out = sqrt(Pin) - 1i*kappa*(a_steady(1)+1i*a_steady(2));
%P_out = abs(s_out)^2
end

4 Comments

The error is saying that in
[a_steady, ~, exitflag, ~] = fsolve(@(x) equilibrium(x, Wl, Pin, T0), [real(a_steady)*1e16 imag(a_steady)*1e16], opt);
That your equilibrium function does not expect 4 parameters being passed to it.
You did not happen to post the code for equilibrium so we do not know how many parameters it does expect.
Hello,this is the function 'equilibrium'
function y = equilibrium(x, Wl, Pin, T0)
% Obtains the value of the electric field inside the ring in steady state.
% When equilibrium(x) = 0 we are at equilibrium.
% x(1) --> Real part of the electric field inside the ring
% x(2) --> Imaginary part of the electric field inside the ring
c = 2.997e8;
hbar = 1.05e-34;
% Solve for deltaT iteratively until we converge
deltaT = 0;
prev_sol = Inf;
num_counts = 0;
while abs(deltaT-prev_sol) > 1 && num_counts < 100
prev_sol = deltaT;
% Get deltaT from the provided x, assuming we are close to T0
[gamma_0, gamma_lin, gamma_rad, kappa, ... % loss params
Vring, V_TPA, V_FCA, gamma_disk, gamma_FCA, gamma_TPA, ... % Optical mode volumes and confinements
~, rho_Si, ~, ~, ... % Thermal related stuff, instantaneous value at T+deltaT
gamma_th_eq, Cp_Si_eq, dnSidT_eq, ... % Thermal related stuff, equivalent value (see comments in code)
gamma_r, alfa_p, alfa_n, dnSidNn, dnSidNp, ... % Carrier related stuff
beta_Si, n_Si, ng, ... % Silicon related parameters
Wl, W0, deltaW0_cold, ... % Ring related stuff
dW0dV, tau] ... % Electro-optic driving related stuff
= ring_params(Wl, T0, deltaT, 0, 0);
% For equilibrium considerations, we care abot the thermal
% equivalent values gamma_th_eq, Cp_Si_eq, dnSidT_eq
H = (gamma_FCA*beta_Si*c^2)/(2*hbar*(Wl)*ng^2*V_FCA^2*gamma_r);
G = (gamma_disk/(rho_Si*Cp_Si_eq*Vring*gamma_th_eq));
E = (gamma_TPA*beta_Si*c^2/(V_TPA*ng^2));
F = (alfa_p+alfa_n)*c*H/ng;
a_re = x(1)*1e-16;
a_im = x(2)*1e-16;
u = a_re.^2 + a_im.^2;
deltaT = G*(gamma_lin + E*u + F*u^2)*u;
%abs(deltaT-prev_sol)
%pause
num_counts = num_counts+1;
end
lam = (gamma_rad + gamma_0 + gamma_lin + E*u + F*u^2)/2;
B = deltaW0_cold - (-W0/n_Si)*(dnSidT_eq*G*(gamma_lin+E*u+F*u^2)*u + dnSidNn*(H*u^2*1e-6)^1.05 + dnSidNp*(H*u^2*1e-6)^0.8);
y(1) = - lam*a_re - B*a_im;
y(2) = -lam*a_im + B*a_re - kappa*sqrt(Pin);
end
I do not see anything obviously wrong.
Can you post enough of your code and data for us to be able to execute the reproduce the error?
The code source is as follows, I am trying to run it to study the nonlinear effects in ring resonator. Maybe you can download from the following website, and that would be convenient. It needs to install the optimization toolbox! Thanks!

Sign in to comment.

 Accepted Answer

%f true
fsolve(@equilibrium,...)
Without @(x) inside the fsolve function.call the function name as above with only the function handle without any arguments

2 Comments

still error :
>> run_sims
You need to specify the ring volume. Not included because of NDA错误使用 get_steady_state (第 41 行)
函数或变量 'x' 无法识别。
If that were done, then how would the equilibrium function know the values of Wl, Pin, T0 ?
The existing code looks like a correct use of parameterization.

Sign in to comment.

More Answers (1)

The code source is as follows, I am trying to run it to study the nonlinear effects in ring resonator. Maybe you can download from the following website, and that would be convenient. It needs to install the optimization toolbox! Thanks!

2 Comments

I am not sure, because according to the new error, @(x) maybe required.

Sign in to comment.

Asked:

on 4 Apr 2021

Commented:

on 4 Apr 2021

Community Treasure Hunt

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

Start Hunting!