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
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
