ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
clear allclcfunction [thetadot] = pend(t,theta) % Constants m = 1; b = 0.05; L = 1; g = 9.81; thetadot = zeros(2,1); thetadot(1) = theta(2); thetadot(2) = -(b/m)*theta(2) - (g/L)*sin(theta(1));end% Initial Conditionsinit = [0, 3];% Intervalinterval = linspace(0, 20, 20*24); % 20 seconds x 24 frames per second% Solve[t, theta] = ode45('pend', interval, init);for i=1:length(theta) % Vertical Reference Line x = [0; 0]; y = [0; -1]; % Pendulum Position x_p = [0; sin(theta(i,1))]; y_p = [0; - cos(theta(i,1))]; plot(x,y,x_p, y_p,'LineWidth', 2, x_p(2), y_p(2), 'o', 'MarkerSize', 20, x_p(2), y_p(2), '*', 'MarkerSize', 20) time = round(t(i)); text(-1.2, 1.2, ['Time = ', num2str(time) ]) xlim([-1.5 1.5]) ylim([-1.5 1.5]) legend('Vertical Line', 'Pendulum Position') title('Position of Pendulum') % For Saving File% saveas(gcf,[ num2str(i) '.jpg']);end
very nice ❤which program used for doing this animation ?
Matlab / Octave
Run this code in Matlab / Octave to get these results
very helpful Thank you very much
clear all
clc
function [thetadot] = pend(t,theta)
% Constants
m = 1;
b = 0.05;
L = 1;
g = 9.81;
thetadot = zeros(2,1);
thetadot(1) = theta(2);
thetadot(2) = -(b/m)*theta(2) - (g/L)*sin(theta(1));
end
% Initial Conditions
init = [0, 3];
% Interval
interval = linspace(0, 20, 20*24); % 20 seconds x 24 frames per second
% Solve
[t, theta] = ode45('pend', interval, init);
for i=1:length(theta)
% Vertical Reference Line
x = [0; 0];
y = [0; -1];
% Pendulum Position
x_p = [0; sin(theta(i,1))];
y_p = [0; - cos(theta(i,1))];
plot(x,y,x_p, y_p,'LineWidth', 2, x_p(2), y_p(2), 'o', 'MarkerSize', 20, x_p(2), y_p(2), '*', 'MarkerSize', 20)
time = round(t(i));
text(-1.2, 1.2, ['Time = ', num2str(time) ])
xlim([-1.5 1.5])
ylim([-1.5 1.5])
legend('Vertical Line', 'Pendulum Position')
title('Position of Pendulum')
% For Saving File
% saveas(gcf,[ num2str(i) '.jpg']);
end
very nice ❤
which program used for doing this animation ?
Matlab / Octave
Run this code in Matlab / Octave to get these results
very helpful
Thank you very much