definitions in a script must appear at the end of the file.

2 次查看(过去 30 天)
Hi
function dndt=imene2022(t,n,)
dndt=zeros(43,1)
%Chemin C
dndt(1)= k1*n(2)*n(32)+k15*n(5)*n(9)+k16*n(5)*n(24)...
+k33*n(4)*n(11)+k40*n(7)*n(25)...
+k72*n(2)*n(22)+k104*n(3)*n(5)+k105*n(3)*n(8)+k106*n(3)*n(23)...
+k117*n(16)*n(2)+k119*n(3)*n(33)+k122*n(11)*n(33)+k124*n(13)*n(33)...
+k130*n(20)*n(33)...
-k10*n(1)*n(22)-k13*n(1)*n(20)...
-k61*n(2)*n(1)...
-k68*n(1)*n(1)-k73*n(1)*n(25)...
-k74*n(1)*n(11)-k75*n(1)*n(21)-k76*n(1)*n(19)-k77*n(1)*n(17)...
-k118*n(1)*n(33)-k136*n(1)*n(3)...
-k139*n(1)*n(6);
%Chemin C+
dndt(2)= -k1*n(2)*n(32)-k5*n(2)*n(15)-k6*n(2)*n(27)...
-k61*n(2)*n(1)-k72*n(2)*n(22)...
-k117*n(16)*n(2)+k45*n(7)*n(11)+k73*n(1)*n(25)...
+k74*n(1)*n(11)+k75*n(1)*n(21)+k76*n(1)*n(19)...
+k77*n(1)*n(17)+k118*n(1)*n(33)+k122*n(11)*n(33);
%Chemin C-
dndt(3)= -k14*n(3)*n(22)-k104*n(3)*n(5)...
-k105*n(3)*n(8)-k106*n(3)*n(23)-k119*n(3)*n(33)...
-k136*n(1)*n(3)-k140*n(3)*n(4)-k141*n(3)*n(15)-k142*n(3)*n(7);
%Chemin O:
dndt(4)= k2*n(5)*n(32)+k10*n(1)*n(22)+k13*n(1)*n(20)...
+k14*n(3)*n(22)+k35*n(7)*n(15)+k36*n(7)*n(17)...
+k52*n(15)*n(22)...
+k53*n(15)*n(18)...
+k78*n(5)*n(9)+k80*n(5)*n(27)...
+k81*n(5)*n(15)+k85*n(6)*n(24)...
+k104*n(3)*n(5)+2*k107*n(5)*n(6)+k108*n(5)*n(16)...
+k109*n(6)*n(8)+k120*n(6)*n(33)+2*k126*n(15)*n(33)...
+k128*n(17)*n(33)+k130*n(20)*n(33)+k131*n(22)*n(33)...
-k21*n(4)*n(27)-k22*n(4)*n(27)-k23*n(4)*n(18)...
-k30*n(4)*n(19)-k31*n(4)*n(14)...
-k33*n(4)*n(11)...
-k82*n(4)*n(19)-k83*n(4)*n(21)...
-k133*n(4)*n(32)-k140*n(3)*n(4)-k143*n(4)*n(6);
%Chemin O+:
dndt(5)= k5*n(2)*n(15)+k34*n(8)*n(15)+k82*n(4)*n(19)...
+k83*n(4)*n(21)+k128*n(17)*n(33)...
-k21*n(4)*n(27)-k22*n(4)*n(27)...
-k23*n(4)*n(18)...
-k30*n(4)*n(19)-k31*n(4)*n(14)...
-k33*n(4)*n(11)...
-k82*n(4)*n(19)...
-k83*n(4)*n(21)-k133*n(4)*n(32)-k140*n(3)*n(4)...
-k143*n(4)*n(6);
%Chemin O-:
dndt(6)= k133*n(4)*n(32)...
........
...........
end
%constantes::
%temperature
T=17000
%constante k: recombinaison radiative
k1=2.36 *(1e-12)*(T/300)^(-0.29)*exp(17.60/T)
k2 =3.24 *(1e-12) *(T/300)^(-0.66)
k3=3.50 *(1e-12)*(T/300)^(-0.53)* exp(3.20/T)....
........
%initial
IC=10^19*ones(1,43)
[t,n]=ode45(@imene2021,[0 1e-3],IC)
plot(t,n)
end
Error: File: imene2022.m Line: 212 Column: 1
Function definitions in a script must appear at the end of the file.
Move all statements after the "imene2022" function definition to before the first local function definition.

回答(1 个)

Scott MacKenzie
Scott MacKenzie 2021-5-29
Functions defined in a script (such as imeme2022 in your script) must be positioned at the end of the script. The error message is clear enough. So, reposition these statements...
%constantes::
%temperature
T=17000
%constante k: recombinaison radiative
k1=2.36 *(1e-12)*(T/300)^(-0.29)*exp(17.60/T)
k2 =3.24 *(1e-12) *(T/300)^(-0.66)
k3=3.50 *(1e-12)*(T/300)^(-0.53)* exp(3.20/T)....
........
%initial
IC=10^19*ones(1,43)
[t,n]=ode45(@imene2021,[0 1e-3],IC)
plot(t,n)
end
above the function definition. BTW, the last line above is a dangling end statement and should be removed.

Community Treasure Hunt

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

Start Hunting!

Translated by