フィルターのクリア

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 回表示 (過去 30 日間)
Jack
Jack 2024 年 1 月 4 日
回答済み: Walter Roberson 2024 年 1 月 4 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by