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

조회 수: 2 (최근 30일)
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

답변 (1개)

Walter Roberson
Walter Roberson 2024년 1월 4일
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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by