MATLAB: ODE45 Dimensions being Concatenated error

matrix dimension consistentode45

Still rather new to MatLab, trying to get ODE45 to work and get the error: Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error in
EP_HW2>@(t,x)[x(4),x(5),x(6);(T/x(7))*x(4)/(sqrt(x(4)^2+x(5)^2+x(6)^2))-mu*x(1)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;(T/x(7))*x(5)/(sqrt(x(4)^2+x(5)^2+x(6)^2))-mu*x(2)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;(T/x(7))*x(6)/(sqrt(x(4)^2+x(5)^2+x(6)^2))-mu*x(3)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;-T/(Isp*g);]'
Error in EP_HW2>@(t,x)dxdt(t,x)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in EP_HW2 (line 14)
[t,x] = ode45(@(t,x) dxdt(t,x), [0 tf], x0);
My code is as follows:
mdry = 20000; T = 1; Isp = 2000; g = 9.8; mu = 1.327*10^(20);
mfuel = 10000; %THIS IS THE FUEL WE ARE CHANGING
%We can find the final time by using a constant thrust function:
tf = mfuel/(T/(Isp*g));
%x = [x, y, z, vx, vy, vz, m]
x0 = [0, -1.496*10^(11), 0, 2.978*10^(4), 0, 0, mdry+mfuel]';
syms t x T mu Isp g
[t,x] = ode45(@(t,x) dxdt(t,x), [0 tf], x0);
dxdt = @(t,x)[
x(4);
x(5);
x(6);
(T/x(7))*x(4)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(1)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
(T/x(7))*x(5)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(2)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
(T/x(7))*x(6)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(3)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
-T/(Isp*g)
];
Really don't know what I'm supposed to be doing to fix this.

Best Answer

Look more carefully at your code. You have
syms t x T mu Isp g
[t,x] = ode45(@(t,x) dxdt(t,x), [0 tf], x0);
dxdt = @(t,x)[
x(4);
x(5);
x(6);
(T/x(7))*x(4)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(1)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
(T/x(7))*x(5)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(2)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
(T/x(7))*x(6)/(sqrt(x(4)^2+x(5)^2+x(6)^2)) - mu*x(3)/(sqrt(x(1)^2+x(2)^2+x(3)^2))^3;
-T/(Isp*g)
];
You use T inside of dxdt but T is not a parameter to the function (the function parameter is t with lowercase), so the T inside the function would be the T from "syms T". If your dxdt worked then then dxdt would return a symbolic result, which is not permitted for ode45. Your dxdt also uses mu, Isp and g, all of which are also assigned by the "syms" call.
Or perhaps your T is from T=1?? It sure is confusing when you use the same variable name for two things and you show the assignment to dxdt in a place where it cannot possibly be used for the preceding ode45() call...
When I move the dxdt definition to before the "syms" and leave out the "syms" then the code appears to work for me.