
function dx=odefun2(t,x)
dx=zeros(2,1);%存盤x1,x2的導數
dx(1)=x(2);%第一個方程
dx(2)=-20*x(2)-100*x(1);%第二個方程
[t,x]=ode45('odefun2',[0,4],[1;0])



注:數值解僅僅是解的一個資料點列;數值解只能作定量分析,它能處理幾乎所有的方程,

xt=dsolve('D2x+20*Dx+100*x=0','x(0)=1','Dx(0)=0')

給出數值解與決議解的對比圖:
f=inline(xt)
plot(t,x(:,1),'r.',t,f(t),'b');
legend('數值解','決議解')

變數名=inline(’函式運算式’,‘變數名1’,‘變數名2’,…,‘變數名n’)

function dx=odefun3(t,x)
global c;
dx=zeros(2,1);%存盤x1,x2的導數
dx(1)=x(2);%第一個方程
dx(2)=-20*c*x(2)-100*x(1)%第二個方程
注:通過全域變數c來接收外部阻尼系數的值,
function ode3(vc)
global c;%全域變數
hold on%hold住圖形視窗
tspan=linspace(0,4,100);
for i=1:length(vc);
c=vc(i);
[t,x]=ode45('odefun3',tspan,[1,0]);
text(t(10),x(10,1),['\leftarrow c',num2str(c)])
plot(t,x(:,1))
end
hold off
vc=[0.2,0.4,0.6,0.8,1]
ode3(vc);

vc=[0.2,0.3,0.4,0.6,0.8,1,1.4,1.7];
ode3(vc);

微信“影像處理與模式識別研究所”關注我呦
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/131843.html
標籤:其他
