Error "using symengine>@()0.0" in ODE Solver

1 回表示 (過去 30 日間)
Tom Keaton
Tom Keaton 2019 年 8 月 24 日
編集済み: Tom Keaton 2019 年 8 月 25 日
Hello,
I restarted everything I did from scratch and in the most simpliest way possible to recreate the same error I get in my much larger code. This error occurs when I make the B-field components functions instead of constants as the E parts are currently defined in this specfiic example. However, in my much larger code this error occurs when I just change the syntax of the ode set so if this error can be resolved here, perhaps then I can figure out why it's happening in the larger code set.
Error:
Error using symengine>@()0.0
Too many input arguments.
Error in reffun (line 14)
ode1 = Ex + s(2).*Bz(s(4),s(5),s(6)) - s(3).*By(s(4),s(5),s(6));
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 diffiqtest (line 7)
[t,S] = ode15s(@reffun,tspan,s0);
Here is the main code:
v0 = [0 0 0];
p0 = [0 0 0];
s0 = [v0 p0];
tspan = [0 5];
[t,S] = ode15s(@reffun,tspan,s0);
Function where ODEs are defined:
function refsolve = reffun(t,s)
Ex = 0;
Ey = 0;
Ez = 0;
persistent Bx By Bz
%Used so that the B-field function is only run once
if isempty(Bx)
[Bx, By, Bz] = B_test();
end
%Reference: s(1) = vx, s(2) = vy, s(3) = vz, s(4) = x, s(5) = y, s(6) = z
ode1 = Ex + s(2).*Bz(s(4),s(5),s(6)) - s(3).*By(s(4),s(5),s(6));
ode2 = Ey + s(3).*Bx(s(4),s(5),s(6)) - s(1).*Bz(s(4),s(5),s(6));
ode3 = Ez + s(1).*By(s(4),s(5),s(6)) - s(2).*Bx(s(4),s(5),s(6));
ode4 = s(1);
ode5 = s(2);
ode6 = s(3);
refsolve = [ode1; ode2; ode3; ode4; ode5; ode6];
end
B_test function:
function [Bx, By, Bz] = B_test()
%Bfieldstrength = 0.64; %In (Teslas)
Bfieldstrength = 0;
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

採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 24 日
When you call matlabFunction pass
'vars', r
  6 件のコメント
Walter Roberson
Walter Roberson 2019 年 8 月 24 日
I have attached the exact files I used.
Tom Keaton
Tom Keaton 2019 年 8 月 25 日
編集済み: Tom Keaton 2019 年 8 月 25 日
It is odd. Your files work, but mine do no even with the same definitions. Why is this the case? Also, when I try plotting the solution, it is incorrect, because I know the solution should not look the way it does. If the ode solver is not solving the equations correctly, and it is not outputting an error, what should I do in this sitatuon?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by