⛄一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【机械仿真】基于matlab模拟刚体不稳定自由旋转【含Matlab源码 7202期】
点击上面蓝色字体,直接付费下载,即可。
获取代码方式2:
付费专栏Matlab物理应用(初级版)
备注:
点击上面蓝色字体付费专栏Matlab物理应用(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab物理应用(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码
⛄二、部分源代码
close all;
clear all;
%-------------------------------------------------------------------------------
STDOUT = 1;
%-------------------------------------------------------------------------------
[ …
operatingSystemArchitectureName …
] = computer( );
%-------------------------------------------------------------------------------
WINDOW_OS_INDICATOR = ‘PCWIN64’;
LINUX_OS_INDICATOR = ‘GLNXA64’;
%-------------------------------------------------------------------------------
switch( operatingSystemArchitectureName )
%{----------------------------------------------------------------------
case( ‘PCWIN64’ )
%{----------------------------------------------------------------
% Operating system is MS Windows 64 bit.
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Set directory separator character.
%-----------------------------------------------------------------
directorySeparator = ‘’;
%}----------------------------------------------------------------
%-----------------------------------------------------------------------
case( ‘GLNXA64’ )
%{----------------------------------------------------------------
% Operating system is Linux 64 bit.
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Set directory separator character.
%-----------------------------------------------------------------
directorySeparator = ‘/’;
%}----------------------------------------------------------------
%-----------------------------------------------------------------------
otherwise
%{----------------------------------------------------------------
% Default operating system.
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% There is no default operating system.
% Generate an error message.
%-----------------------------------------------------------------
[ …
errorMessageString …
] = …
sprintf …
( …
[ …
‘\n\n\n’ …
‘%s\n%s\n%s\n%s\n%s\n’ …
‘%s"%s"\n’ …
‘%s\n%s\n%s\n%s\n’ …
‘\n\n\n’ …
], …
‘--------------------------------------------------’, …
‘|’, …
‘| ERROR:’, …
‘|’, …
‘| Encountered unknown operating system.’, …
'| Operating System Indicator was: ', …
operatingSystemArchitectureName, …
‘|’, …
‘| Program will terminate.’, …
‘|’, …
‘--------------------------------------------------’ …
);
%-----------------------------------------------------------------
% Terminate the program.
%-----------------------------------------------------------------
error( errorMessageString );
%}----------------------------------------------------------------
%}----------------------------------------------------------------------
end;
%===============================================================================
currentWorkingDirectoryPath = cd;
%-------------------------------------------------------------------------------
sourceCodeDirectory1 = [ …
currentWorkingDirectoryPath, …
directorySeparator, …
‘Utilities’
];
%-------------------------------------------------------------------------------
addpath( genpath( sourceCodeDirectory1 ) );
%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
% Generate purpose message.
%-------------------------------------------------------------------------------
generateFreeUnstableRigidBodyRotationDemoPurposeMessage( );
%-------------------------------------------------------------------------------
% Generate usage message.
%-------------------------------------------------------------------------------
generateFreeUnstableRigidBodyRotationDemoUsageMessage( );
%-------------------------------------------------------------------------------
% Define the unstable free rotation of a rigid body demonstration.
%-------------------------------------------------------------------------------
fprintf …
( …
STDOUT, …
[ …
‘\n\n\n’ …
‘%s\n%s\n%s\n%s\n%s\n’ …
‘\n\n\n’ …
], …
‘------------------------------------------------------------------’, …
‘|’, …
‘| UNSTABLE FREE ROTATION RIGID BODY DEMONSTRATION:’, …
‘|’, …
‘------------------------------------------------------------------’ …
);
%-------------------------------------------------------------------------------
%
% Specify unstable free rotation of a rigid 3D rectangular block by
% assigning dominant angular velocity about body axis with intermediate
% inertia value (body axis length proportional to inertia value).
%
%-------------------------------------------------------------------------------
simulationEndTime = 1.0E3;
numberSampleTimes = 1.0E6;
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
momentOfInertiaMatrix = diag( [ 4.0, 1.0, 9.0 ]);
initialRotationVectorBodyCoord = [ 1.0 ; 0.0; 0.0 ];
initialAngularVelocityBodyCoord = [ 0.10; 0.00001; 0.0 ];
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ …
demonstrationTitle …
] = sprintf …
( …
‘%s’, …
‘UNSTABLE FREE ROTATION RIGID BODY DEMONSTRATION’ …
);
%-------------------------------------------------------------------------------
colorDefinitions;
%-------------------------------------------------------------------------------
% profile on;
%-------------------------------------------------------------------------------
fprintf …
( …
STDOUT, …
[ …
‘\n\n\n’ …
‘%s\n%s\n%s\n%s\n%s\n’ …
‘\n\n\n’ …
], …
‘------------------------------------------------------------------’, …
‘|’, …
‘| Generating body kinematics at each time sample:’, …
‘|’, …
‘------------------------------------------------------------------’ …
);
%-------------------------------------------------------------------------------
% Generate solution for specified torque free rotation of specified rigid
% body at each sample time.
%-------------------------------------------------------------------------------
[ …
timeSampleValues, …
rotationVectorsBodyCoords, …
angularVelocitiesBodyCoords …
] = generateSolutionsForFreeRotationRigidBodyKinematics …
( …
momentOfInertiaMatrix, …
initialRotationVectorBodyCoord, …
initialAngularVelocityBodyCoord, …
numberSampleTimes, …
simulationEndTime …
);
%-------------------------------------------------------------------------------
numberTimeSamples = length( timeSampleValues );
%-------------------------------------------------------------------------------
% Angular momentum values is calculated as the product of the moment
% of inertia matrix and the angular velocity vectors.
%-------------------------------------------------------------------------------
angularMomentumsBodyCoords = …
momentOfInertiaMatrix * …
angularVelocitiesBodyCoords;
⛄三、运行结果
⛄四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 门云阁.MATLAB物理计算与可视化[M].清华大学出版社,2013.
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除