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

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일

0 개 추천

When you call matlabFunction pass
'vars', r

댓글 수: 6

Tom Keaton
Tom Keaton 2019년 8월 24일
편집: Tom Keaton 2019년 8월 24일
Sorry, could you clarify? Like adding r to syms?
syms x y z r
Or?
Bx = matlabFunction(B(1),'vars',r);
By = matlabFunction(B(2),'vars',r);
Bz = matlabFunction(B(3),'vars',r);
Either way I get the same error.
Bx = matlabFunction(B(1), 'vars', r);
By = matlabFunction(B(2), 'vars', r);
Bz = matlabFunction(B(3), 'vars', r);
Without this, the expression is examined with symvar to generate the list of parameters -- so for example if you had an expression that happened to come out as x^2+y then matlabFunction would by default create a function with parameters (x,y) but not z, and if the expression happened to come out as x^2+z then matlabFunction would by default create a function with parameters (x,z) without y. Looking through the expression to find the variables is normally the Right Thing To Do -- but it fails if you have a fixed calling sequence like you do in your case.
You need to
clear reffun
in order to clear the persistent results that you memorized on an earlier run.
Tom Keaton
Tom Keaton 2019년 8월 24일
편집: Tom Keaton 2019년 8월 24일
I see, but I still get the exact same error when I change it to this and clear reffun.
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개)

카테고리

태그

질문:

2019년 8월 24일

편집:

2019년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by