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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章