how to remove error in the code?

3 views (last 30 days)
Muhammad
Muhammad on 18 Sep 2022
Answered: Torsten on 18 Sep 2022
this is the matlab code that in made and i am getting the errors so any one who can correct my code?
tic
% this is the spectrum file
clear
%%%%%%%
% our known parameters (for L4) at 2Ith
% Sp. Em. lifetime
ts=0.43*10^-9;
% Photon lifetime
tp=1.8*10^-12;
% Mode spacing
fd=90*10^9;
% Gain corfficient
Gn=1.4*10^-12;
% carrier density to reach zero gain (this value can be modified so the
% theoritical value of ROF fits the characterized one.
No=0.5*10^24;
% carrier density at threshold
Nth=No+(1/(Gn*tp));
%free running electric field
Eos=sqrt(tp*Nth/ts);
%%%%%%
global I00
global I01
global I02
global I10
global I20
%global K00
% detuning
global f00
global f01
global f02
global f10
global f20
UU=zeros(1,80);
PPP=zeros(80,80);
for h=1:80
f00=(-20*10^9)+(0.5*h*10^9);% central frequency % step here must be 0.1 GHz for the allocation of ML2 see line 71 and 72
DLT=0.6*10^9 ;% spacing
f01=f00+DLT;
f02=f01+DLT;
f10=f00-DLT;
f20=f10-DLT;
for v=1:80
K00=0.0+(0.01*v);
K01=K00;
K02=K00;
K10=K00;
K20=K00;
E00=K00*Eos;
E01=K01*Eos;
E02=K02*Eos;
E10=K10*Eos;
E20=K20*Eos;
I00=10*log10(K00^2);
I01=10*log10(K01^2);
I02=10*log10(K02^2);
I10=10*log10(K10^2);
I20=10*log10(K20^2);
t =linspace(-25*10^-9,25*10^-9, 100000); % NB:the time step=50ns/100000=0.5ps , the start time chosen so that desired spectra begins at 0.
C0 = [Eos 0 No]; % NB:This is our initial conditions, using Eo as 2.16*10^10 gives different spectra especially in the locking state
[t,C] = ode45('star4', t, C0); % Solve the system according to the time span (ode45 is based on Runge-Kutta method)
Ei=abs(C(:,1)).*exp(1i*C(:,2)); % complex E
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f11=t*4*10^19; % conversion of time to frequency (with a corrction factor)
% eliminating the initial behaviour by excluding quarter of the data
%Eii=Ei(30000:100000,1);
%f1=f(30000:100000,1);
%FFT
X = abs(fft(Ei));
X = fftshift(X);
%chosing window of FFT
X1 = X(48000:52000,1); % real electric field
f22 = f11(48000:52000,1)-(0.01*10^9); % frequency (with small shifting so that the free running peak aligned with zero (in the case of weak injection -(0.01*10^9))
%chosing window of E
EE = abs(C(90000:100000,1)); % real electric field
tt = t(90000:100000,1); % time
%%%%%%%% this to sample the FFT and to serch for local peaks
%%%%
PE = find(X1 == max(X1)); % the SL peak
XX=X1(PE,1); % value of the peak
FF=f22(PE,1);%
%%%
%PR = ((ZZ(1,1)-ZZ(2,1))/ZZ(1,1)); % calculating the power ratio of the peak and the sideband to examin the stability
if FF <= f00+(0.01*10^9)&& FF >= f00-(0.01*10^9)
UU(v) = 0;
else
UU(v) = 0-FF;
end
PPP(h,v)=UU(v);
end
end
toc
errors
>> maps
Error using feval
Unrecognized function or variable 'star4'.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in maps (line 85)
[t,C] = ode45('star4', t, C0); % Solve the system according to the time span (ode45 is based on Runge-Kutta
method)

Answers (1)

Torsten
Torsten on 18 Sep 2022
And where is the fiunction "star4" ?
Your call should be
[t,C] = ode45(@star4, t, C0); % Solve the system according to the time span (ode45 is based on Runge-Kutta method)
at least if the function "star4" has the usual parameter list
function dy = star4(t,y)

Categories

Find more on Mathematics 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!