在我的ODE解算器中收到“输入参数过多”错误

时间:2019-04-15 16:38:09

标签: matlab

我继续收到以下错误:“使用symengine时出错> @()0.0 输入参数过多。”,但是我正在运行的另一段代码中使用了完全相同的ode解算器和ode的解算器,但没有得到相同的错误。我逐行遍历了整个代码以试图找出原因现在已经进行了4个多小时,无法弄清为什么会发生这种情况。这里提出的任何建设性建议都将不胜感激。

Error using symengine>@()0.0
Too many input arguments.
Error in bdipuniodefun (line 17)
bdip = [s(4); s(5); s(6); (q/m_e)*(Ex(s(1),s(2),s(3)) + s(5)*Bz(s(1),s(2),s(3)) - s(6)*By(s(1),s(2),s(3)));
(q/m_e)*(Ey(s(1),s(2),s(3)) + s(6)*Bx(s(1),s(2),s(3)) - s(4)*Bz(s(1),s(2),s(3))); (q/m_e)*(Ez(s(1),s(2),s(3)) +
s(4)*By(s(1),s(2),s(3)) - s(5)*Bx(s(1),s(2),s(3)))];
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in collisions (line 195)
        [T,S] = ode15s(@bdipuniodefun, tspan, icv);

我已经逐行检查了代码,错误似乎源于bdip矩阵定义。当我尝试使用以下直接输入运行该函数时:“ bdipuniodefunetest(1,[1; 1; 1; 1; 1; 1; 1;]))”仍然会给我同样的错误。不过,真正奇怪的是,当我用另一段使用完全相同的矩阵和求解器的代码进行相同的直接输入时,它运行得很好。

这可能看起来像很多代码,但是此ode求解器和ode起作用的其他文件大约有300多行。但是,我知道这些附加行都不会对这个错误有任何影响,因为它们不影响求解器的任何输入。

%User inputs
%TSTEP MUST BE ABLE TO GO INTO TFIN AN ODD AMOUNT OF TIMES (Because simulation includes tstep @ 0 so it ends up being even)
tstep = 0.25E-7; %Defining time step
tfin = 3E-7; %Defining final time
ienergy = 1E-19;
%Initial conditions to solve for pitch angle and lambda value
lambdacheck = 60; %In degrees
options = odeset('RelTol',tstep,'AbsTol',tstep);
sine2alpha = (cosd(lambdacheck)^6)/sqrt(1+3*sind(lambdacheck)^2);
m_e = 9.11E-31;
v0mag = sqrt(2*ienergy/m_e);
vx = 0;
vy = sqrt(sine2alpha)*v0mag;
vz = sqrt(1 - sine2alpha)*v0mag;
x = 0.03;
y = 0;
z = 0;

icposition = [x,y,z];
icvelocity = [vx,vy,vz];

initial electron velocities, collision position, mfp and energy matrix will be saved
tic %Begin timer
%Create zeros matrices to populate later
intspan = [0:tstep:tfin]; %Total time span
intspancol = intspan(:); %inverts matrix's rows and columns
[introw,intcol] = size(intspancol);

%Generate matrix that will be populated by positions and velocities (Each matrix within structure "Wposandvel" should be of size 2*introw-1 by 6)
Wposandvel = zeros(2*introw-1,6);

%This section is purely for generating matrices the program will populate later
tindex = [0:1:introw-2];
tindexcol = tindex(:); %inverts matrix's rows and columns
[tinrow,tincol] = size(tindex);

for t = 0:1:introw-2 %complete time interval and time step

        [trow,tcol] = size(t);
        r = sqrt(x.^2 + y.^2 + z.^2);
    vmag = sqrt(vx.^2 + vy.^2 + vz.^2);

    %Coupled differential equation solver for trajectory within current time step
    icv = [x; y; z; vx; vy; vz]; %Initial conditions
        tspan = [intspan(t+1) ((intspan(t+2)-intspan(t+1))/2)+intspan(t+1) intspan(t+2)]; %Time span

        tic
        %Trajectory solver
        [T,S] = ode15s(@bdipuniodefunetest, tspan, icv);
        [rownum,colnum] = size(S);
        Wposandvel((1+2*t):(3+2*t),(1:6)) = S;
        toc

        %Redfine the velocity and position components to reference on next if-loop run
        x = Wposandvel((3+2*t),1);
        y = Wposandvel((3+2*t),2);
        z = Wposandvel((3+2*t),3);
        vx = Wposandvel((3+2*t),4);
        vy = Wposandvel((3+2*t),5);
        vz = Wposandvel((3+2*t),6);


end
function bdip = bdipuniodefunetest(t,s)

%Using SI units
q_e = -1.60217662E-19;
m_e = 9.11E-31;

persistent Bx By Bz Ex Ey Ez

if isempty(Bx)
    [Bx, By, Bz] = B_test();
end

if isempty(Ex)
    [Ex, Ey, Ez] = E_test0();
end

bdip = [s(4); s(5); s(6); (q_e/m_e)*(Ex(s(1),s(2),s(3)) + s(5)*Bz(s(1),s(2),s(3)) - s(6)*By(s(1),s(2),s(3))); (q_e/m_e)*(Ey(s(1),s(2),s(3)) + s(6)*Bx(s(1),s(2),s(3)) - s(4)*Bz(s(1),s(2),s(3))); (q_e/m_e)*(Ez(s(1),s(2),s(3)) + s(4)*By(s(1),s(2),s(3)) - s(5)*Bx(s(1),s(2),s(3)))];

end
function [Bx, By, Bz] = B_test()

Bfieldstrength = 0.64; %In (Teslas)
magvol = 3.218E-6; %In (m)
mu0 = (4*pi)*10^-7;
magnetization = (Bfieldstrength*magvol)/mu0;

syms x y z
m = [0,0,magnetization];
r = [x, y, z];
B = mu0 *(((dot(m,r)*r*3)/norm(r)^5) - m/norm(r)^3);
Bx = matlabFunction(B(1));
By = matlabFunction(B(2));
Bz = matlabFunction(B(3));

end
function [Ex, Ey, Ez] = E_test0()

syms x y z
R_s = 0.02;
V = 0;
epnaut = 8.854187E-12;
k = 1/(4*pi*epnaut);
Q = (V*R_s)/k;
r = [x, y, z];
E = (k*Q/norm(r)^3)*r;
Ex = matlabFunction(E(1));
Ey = matlabFunction(E(2));
Ez = matlabFunction(E(3));

end

bdip全部在一行上的原因是因为ODE求解器实际上将ode放在不同的行上来求解ode(当我将它放在一行上时它不计算E部分现在)

0 个答案:

没有答案