Pendulum equations setup help

조회 수: 2 (최근 30일)
william Smith
william Smith 2019년 3월 24일
답변: NVSL 2025년 6월 11일
%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

답변 (1개)

NVSL
NVSL 2025년 6월 11일
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!

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by