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

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 24 Aug 2019
When you call matlabFunction pass
'vars', r
  6 Comments
Tom Keaton
Tom Keaton on 25 Aug 2019
Edited: Tom Keaton on 25 Aug 2019
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?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!