声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 7525|回复: 24

[线性振动] Runge-Kutta实现多自由度系统响应的MATLAB程序

  [复制链接]
发表于 2006-11-21 19:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
function z = vbr_rk(rkf,u,t,x0)
%vbr_rk   vbr_rk(rkf,u,t,x0)
%       Runge-Kutta fourth order solution to a first order DE
%       t is a row vector from the initial time to the final time
%       step h.  
%       x0 is the initial value of the function.
%       The force matrix u is ordered such that the nth column of u is the force vector u evaluated at time n*dt.
%       rkf is a variable containing the name of the function file.  
%       The equations in the function file must be written in first order state space form.
%       See example vbr_rk_ex.m.
%       Example
%       t=0:.5:20;                             % Creates time vector
%       u=[zeros(1,length(t));sin(t*1.1)];     % Creates force matrix
%       x0=[1 ;0];                             % Creates initial state vector.
%       x=vtb1_3('vbr_rk_ex',u,t,x0);           % Runs analysis.
%       plot(t,x(1,:));                        % Plots displacement versus time.
%       plot(t,x(2,:));                        % Plots velocity versus time.

n=length(t);
z=zeros(length(x0),length(t));
z(:,1)=x0;
h=t(2)-t(1);

for l1=1:(n-1);
   z1=z(:,l1);
   u1=u(:,l1);
   u2=u(:,l1+1);

   k1=h*feval(rkf,z1,u1,t(l1));
   k2=h*feval(rkf,z1+.5*k1,u1,t(l1)+.5*h);
   k3=h*feval(rkf,z1+.5*k2,u1,t(l1)+.5*h);
   k4=h*feval(rkf,z1+k3,u1,t(l1)+h);
   z(:,l1+1)=z(:,l1)+1/6*(k1+2*k2+2*k3+k4);
end
其中rkf为动力微分方程,形如
function [zd]=vbr_rk_ex(z,u,t)
%    function for    2
%                  dx      dx
%                m --  + c -- +k x = f(t)
%                    2     dt
%                  dt                     dx
%    where m=1,k=1,c=.1, and z(1)=x, z(2)=--
%                                         dt
zd=[z(2);
    -.1*z(2)-z(1)+u(2)];

点评

赞成: 5.0
赞成: 5
很不错的程序!!!但是希望LZ利用“<>”功能,方便大家!  发表于 2014-3-25 23:56

评分

1

查看全部评分

回复
分享到:

使用道具 举报

发表于 2006-11-21 19:22 | 显示全部楼层
这个程序我没有看懂,是不是太特殊了。怎么没有地震波的输入
 楼主| 发表于 2006-11-21 19:28 | 显示全部楼层
u表示激励输入
对于多自由度,关键在于rkf的形式
 楼主| 发表于 2006-11-25 18:52 | 显示全部楼层
不客气!大家互相学习!
发表于 2007-3-30 15:54 | 显示全部楼层
这个程序怎么总出错?提示如下
??? Error: File: E:\MATLAB6p5p1\work\vbr_rk.m Line: 23 Column: 16
Missing variable or function.
怎么才能让程序计算呢?请解答,谢谢!
发表于 2007-3-31 07:01 | 显示全部楼层
原帖由 handb 于 2007-3-30 15:54 发表
这个程序怎么总出错?提示如下
??? Error: File: E:\MATLAB6p5p1\work\vbr_rk.m Line: 23 Column: 16
Missing variable or function.
怎么才能让程序计算呢?请解答,谢谢!


应该是参数没给对,仔细研究一下程序的注释
发表于 2007-3-31 09:48 | 显示全部楼层
先谢谢多情清秋,但我用的是程序中的exemple啊???
发表于 2007-3-31 09:57 | 显示全部楼层
也就是这一段
%       Example
       t=0:.5:20;                             % Creates time vector
      u=[zeros(1,length(t));sin(t*1.1)];     % Creates force matrix
       x0=[1 ;0];                             % Creates initial state vector.
       x=vtb1_3('vbr_rk_ex',u,t,x0);           % Runs analysis.
%上一个语句无法调用子程序,我改为z=vbr_rk('vbr_rk_ex',u,t,x0); 否则提示找不到子程序         
       plot(t,z(1,:));                        % Plots displacement versus time.
      plot(t,z(2,:));                        % Plots velocity versus time.
结果出现我描述的错误,烦请高人指点,谢谢
发表于 2007-4-2 20:36 | 显示全部楼层

回复 #2 wei124 的帖子

Runge-Kutta法是自启动的。
记得硕士论文答辩时,一个老师也这样问过:你这没有初始条件,难道系统就自己振动起来了?
当时一下子把我问蒙了,确实嘛,离开了激励,也没有初始条件,自己就振动起来了,没道理。呵呵。
发表于 2007-4-3 21:03 | 显示全部楼层
正确的代码
  1. t=0:.5:20;                             % Creates time vector
  2. u=[zeros(1,length(t));sin(t*1.1)];     % Creates force matrix
  3. x0=[1 ;0];                             % Creates initial state vector.
  4. x=vbr_rk('vbr_rk_ex',u,t,x0);           % Runs analysis.
  5. plot(t,z(1,:));                        % Plots displacement versus time.
  6. plot(t,z(2,:));                        % Plots velocity versus time.
复制代码
建议楼主简单学习一下matlab,如果你要用matlab程序的话

[ 本帖最后由 无水1324 于 2007-7-23 13:29 编辑 ]

点评

plot(t,x(1,:)); plot(t,x(2,:));  发表于 2011-12-17 21:53

评分

1

查看全部评分

发表于 2011-6-22 00:15 | 显示全部楼层
问下 ,如果是二自由度的动力学方程,那rkf该怎么构造呢?
发表于 2011-10-30 13:42 | 显示全部楼层
我在找这个程序呢
发表于 2011-11-4 21:53 | 显示全部楼层
谢谢楼主!!!!!!!!!!
发表于 2011-11-14 16:47 | 显示全部楼层
自己编也不困难吧,还能自己设定很多参数,自己还明白怎么设定参数
发表于 2011-11-28 16:46 | 显示全部楼层
每天来这里的目的就是为了学习,期待着有一天也能为这个论坛做一点贡献。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-19 11:10 , Processed in 0.054538 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表