Clear Filters
Clear Filters

"Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0."

3 views (last 30 days)
I'm trying to run a CR3BP script. It keeps saying that dS(4,1) is a 1 by 1 and and the right side of the equation is 0 by 0. I can't figure out why:
function [dS] = CR3BP(~, s, mu, ~)
% Initialize state at input epoch t.
dS = zeros(6,1);
% Retrieve components from current state.
x = s(1,1);
y = s(2,1);
z = s(3,1);
vx = s(4,1);
vy = s(5,1);
vz = s(6,1);
% Compute the distance from the smaller primary.
r_1 = sqrt((x + mu - 1)^2 + y^2 + z^2);
% Compute the distance from the larger primary.
r_2 = sqrt((x + mu)^2 + y^2 + z^2);
% Assign velocities along x, y and z axes of the CR3BP rotating-frame.
dS(1,1) = vx;
dS(2,1) = vy;
dS(3,1) = vz;
% Assign accelerations along x, y and z axes of the CR3BP rotating-frame,
% using equations of motion from the CR3BP model.
dS(4,1) = x + 2*vy - (1 - mu)*(x + mu)/(r_2^3) - ...
mu*(x - 1 + mu)/(r_1^3);
dS(5,1) = y - 2*vx - ((1 - mu)*y)/(r_2^3) - (mu*y)/(r_1^3);
dS(6,1) = -((1 - mu)*z)/(r_2^3) - (mu*z)/(r_1^3);
end
-----------------------------------------------------------------------------------------
ERROR below:
Unable to perform assignment because the size of the
left side is 1-by-1 and the size of the right side is
0-by-0.
Error in CR3BP (line 35)
dS(4,1) = x + 2*vy - (1 - mu)*(x + mu)/(r_2^3) - ...
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in Single_Shooting_Lyapunov_Main (line 49)
[t_cor, s_cor] = ode45('CR3BP', cor_tspan, cor_xinit, options);

Accepted Answer

Walter Roberson
Walter Roberson on 15 Aug 2022
I predict that your mu is empty.
function [dS] = CR3BP(~, s, mu, ~)
That function expects 4 parameters.
[t_cor, s_cor] = ode45('CR3BP', cor_tspan, cor_xinit, options);
That syntax is going to call CR3BP with two parameters. I am a bit surprised that you do not get an error in CR3BP about not passing enough arguments.
In order to pass extra parameters to your function you should be using a function handle and parameterize it: http://www.mathworks.com/help/matlab/math/parameterizing-functions.html

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!