MATLAB与高等数学--方程组相平面图(弹簧的阻尼振动图像)

绘制弹簧的位置和动量随时间变化的图像
x(t)表示弹簧系统所在的位置,p(t)表示它的动量,并且遵循方程:

1

  clear,clc;
  syms x(t) p(t);
  q1 = 2*diff(x,t,2)+diff(x,t,1)+8*x==0;
  q2 = diff(p,t,1)==-p-8*x;
  cond1 = x(0)==2;
  cond2 = p(0)==0;
  cond3 = diff(x,t,1);
  s = dsolve(q1,q2,cond1,cond2,cond3(0)==0);
  s.x
  s.p
  ezplot(s.x,[0 10])
  title('质心所在位置')
  ezplot(s.p,[0 10])
  title('动量')

质心随时间变化的图像:
2
动量随时间变化图像:
3
使用ezplot()命令绘制p-x图像:
4
我们可以修改一下其它参数让这个图变得好看一些,首先我们定义下时间间隔值:

 t1 = [0:0.1:10];

现在我们使用subs命令在这个时间间隔产生表示位置与动量函数的数值:

   x1 = subs(s.x,'t',t1);
   p1 = subs(s.p,'t',t1);

现在我们有了数据点,所以我们可以使用plot命令来绘制相图:

   plot(x1,p1),xlabel('x'),ylabel('p'),title('质心动量相图');

现在结果好多了:

5
让我们看看临界阻尼震荡的情况:
6
求解方程:

clear,clc;
syms x(t) p(t);
q1 = diff(x,t,2)+diff(x,t)+x/4==0;
q2 = diff(p,t,1)==-p/2-x/4;
cond1 = x(0)==4;
cond2 = diff(x,t,1);
cond3 = p(0)==0;
s = dsolve(q1,q2,cond1,cond2(0)==0,cond3);
s.x
s.p

解:

ans =
4*exp(-t/2) + 2*t*exp(-t/2) 
ans =
- t*exp(-t/2) - (t^2*exp(-t/2))/4

我们绘制位置随时间变化的图像:

ezplot(s.x,[0 15])
axis([0 15 0 4]);
title('位置');

6
现在绘制动量图像:

explot(s.p,[0 15])
title('动量');

7

发布了98 篇原创文章 · 获赞 18 · 访问量 6558

猜你喜欢

转载自blog.csdn.net/qq_44486550/article/details/105544529