Not enough input arguments.

4 views (last 30 days)
Savanna
Savanna on 14 Jan 2023
Edited: Sulaymon Eshkabilov on 14 Jan 2023
Working with A_new and trying to implement it into the R function but keep getting an error for not enough input arguments.
%Values
GMs = 1.3271244*10^20; %Nm^2/kg
GMe = GMs/332946;
x_1 = -124850219*1000; %km -> m
x_2 = -78506090*1000; %km-> m
v_1 = 15.857131*1000; %km/s-> m/s
v_2 = -25.712187*1000; %km/s->m/s
%astroids
x_1a =-154965574*1000;%km/s->m/s
x_2a = -249465245*1000;%km/s->m/s
v_1a= 24.723504*1000;%km/s->m/s
v_2a = 2.645546*1000;%km/s->m/s
% a anonymous function
x_i = [x_1,x_2];
% x_2D = sqrt(x_1^2+x_2^2); %2D- x
% x_2D = vecnorm(x_i);
% A = @(x) [((-GMs/(x_2D^3))*x_1) ; (-GMs/(x_2D^3))*x_2];
A = @(x) ( -GMs ./ (vecnorm(x).^3)) * x; %Acceleration
A_new= @(x,x_e) (( -GMs ./ (vecnorm(x).^3)) * x) - (GMe ./ (vecnorm(x-x_e).^3)*(x-x_e)); %acceleration with earths gravity
% a_i = [a_1 a_2]
a_i = A(x_i)';
% below is the values I got and they match the values given
a_1 = 5.17; %mm/s^2 ->0.0052 m/s^2
a_2 = 3.25; %mm/s^2 -> 0.0032m/s^2
%b combine arrays into 2x2 matrix
v_i = [v_1,v_2];
v_ia =[v_1a,v_2a];
%u = [x_1, v_1; x_2, v_2]; %Earth
u=[x_1, v_1; x_2, v_2; x_1a, v_1a; x_2a,v_2a];%astroid + Earth
R = @(u) [u(1:2,2),A(u(1:2,1));u(3:4,2),A_new(u(3:4,1))];%based on solution from class
%R = @(u) [u(:,2),A(u(:,1))]; for part b
%R = @(u) [u(1:2,2),A(u(1:2,1));u(3:4,2),A(u(3:4,1))]; for f and g
% R = @(u) [v_i A(x)];
%c Motion of earth over 366 days
% Explicit Euler Scheme
t = 0;
dt = 100;
matrix_u=u(:,1);
while t(end)< 31622400
t(end+1)=t(end)+dt;
%u=expliciteuler(u,dt,R);
u=rungekutta(u,dt,R); %e Runge-Kutta Scheme
matrix_u(:,end+1)=u(:,1);
end
Unrecognized function or variable 'rungekutta'.
figure(1)
plot(matrix_u(1,:),matrix_u(2,:),'g',matrix_u(3,:),matrix_u(4,:),'r') %d plot explicit Euler and e Rungekutta
grid on
legend('Earths Orbit', 'Astroid Orbit')
%g distance between earth and astroid orbit
d = vecnorm( [matrix_u(1, : ) ; matrix_u( 2, : ) ] - [ matrix_u( 3 , : ) ; matrix_u( 4 , : ) ] );
d_o= d*(1/332946);
%d(1:50) % to recall some of the distances
%y=min(d)
[min_value, min_index] = min(d)
[min_value, min_index] = min(d_o)
  1 Comment
Torsten
Torsten on 14 Jan 2023
Could you include the missing function ?

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 14 Jan 2023
Edited: Sulaymon Eshkabilov on 14 Jan 2023
In your A_new, you should have vecnorm known in A_new. If vecnorm() is a norm of a vector x that you are trying to compute, then you had better use this syntax while calling: A_new , e.g.:
A_new= @(x,x_e) (( -GMs ./ (norm(x).^3)) * x) - (GMe ./ (norm(x-x_e).^3)*(x-x_e));
  1 Comment
Walter Roberson
Walter Roberson on 14 Jan 2023
I do not understand what you are saying about vecnorm ?
I am not sure if you are saying that vecnorm is not a Mathworks function? Because it is vecnorm .
Or are you saying that it has been used incorrectly ??

Sign in to comment.

Categories

Find more on Earth and Planetary Science in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!