Effacer les filtres
Effacer les filtres

why do i get this message Not enough input arguments. Error in ODEforA6 (line 9) theta = Y(1); and can someone help me please

1 vue (au cours des 30 derniers jours)
We cannot easily apply a numerical method with a general value for the initial angle. So, we elect to use the initial conditions θ(0) = 0.2 radians and θ ′ (0) = 0. A6) Using ode45 (or an equivalent numerical ODE solver in your choice of mathematical software), solve the system found in Question A5 for 0 ≤ t ≤ 20, subject to the above initial conditions.
%% Solving the ODE
function dYdt = ODEforA6(t, Y)
g = 9.81; % Acceleration due to gravity
L = 1 ; % Length of the pendulum (assign an appropriate value)
theta = Y(1);
omega = Y(2);
dtheta_dt = omega;
domega_dt = -g/L * sin(theta);
dYdt = [dtheta_dt; domega_dt];
initial_conditions = [0.2; 0];
[t, Y] = ode45(@ODEforA6, [0 20], initial_conditions);
%% Plotting the solution
figure;
plot(t, Y(:, 1)); % Plot of theta vs. time
xlabel('Time (s)');
ylabel('Theta (radians)');
title('Solution of the Pendulum ODE');
end

Réponses (1)

Walter Roberson
Walter Roberson le 4 Jan 2024
You tried to execute the code by pressing the green Run button. When you press the green Run button, your code is executed with no input parameters.
But it doesn't matter, as you had the order of your code wrong.
initial_conditions = [0.2; 0];
[t, Y] = ode45(@ODEforA6, [0 20], initial_conditions);
%% Plotting the solution
figure;
plot(t, Y(:, 1)); % Plot of theta vs. time
xlabel('Time (s)');
ylabel('Theta (radians)');
title('Solution of the Pendulum ODE');
%% Solving the ODE
function dYdt = ODEforA6(t, Y)
g = 9.81; % Acceleration due to gravity
L = 1 ; % Length of the pendulum (assign an appropriate value)
theta = Y(1);
omega = Y(2);
dtheta_dt = omega;
domega_dt = -g/L * sin(theta);
dYdt = [dtheta_dt; domega_dt];
end

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by