Pendulum equations setup help
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%setup : t, starts at 0, with time step dt, until tfinal , which is 1000 seconds.
%initialize the x, ? dot, ? double dot, θ, ? dot, and ? double dots and F vectors as zeros, all the same size as t (time).
%Set the first value of the θ vector to θ0
t=(0,1000,dt);
%any help on this I really appreciate it
0 comentarios
Respuestas (1)
NVSL
el 11 de Jun. de 2025
Hey @william Smith
I understand you are trying to initialise few vectors with a pre-defined size. You can do so by using ‘zeros’ function which pre-allocates defined space by initialising the vector with zeroes.
Here's how you can create this setup:
% Time setup
dt = 0.01; % Time step (seconds)
tfinal = 1000; % Final time (seconds)
t = 0:dt:tfinal; % Time vector
% Preallocate variables
x = zeros(size(t)); % Position
x_dot = zeros(size(t)); % Velocity
x_ddot = zeros(size(t)); % Acceleration
theta = zeros(size(t)); % Angle (θ)
theta_dot = zeros(size(t)); % Angular velocity (θ̇)
theta_ddot = zeros(size(t)); % Angular acceleration (θ̈)
F = zeros(size(t)); % Force
% Initial condition
theta0 = deg2rad(10); % Example: initial angle of 10 degrees
theta(1) = theta0; % Set first value of theta
You can modify "dt" and "theta0" as needed. The "deg2rad" function is used to convert degrees to radians — this is optional depending on your unit preference.
More details on how to initialise a vector using “zeros” function can be found from the below documentation link:.
I hope this is beneficial!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!