MATLAB解含參數方程、矩陣方程、二階微分方程組

一、以下公式: 其中x、y、m、n爲參數,a、b爲未知數,利用MATLAB求解方程;spa

 

syms x y m n a b;code

[a,b]=solve('x=m*cos(a)+n*cos(a+b)','y=m*sin(a)+n*sin(a+b)','a','b');blog

會獲得四組解;對a(3)、b(3)、a(4)、b(4)進行化簡,it

simplify(a(3));class

simplify(b(3));im

simplify(a(4));db

simplify(a(4));img

獲得:di

a(3)= 2*atan((2*m*y - (- m^4 + 2*m^2*n^2 + 2*m^2*x^2 + 2*m^2*y^2 - n^4 + 2*n^2*x^2 + 2*n^2*y^2 - x^4 - 2*x^2*y^2 - y^4)^(1/2))/(m^2 + 2*m*x - n^2 + x^2 + y^2));dba

b(3)= 2*atan(((- m^2 + 2*m*n - n^2 + x^2 + y^2)*(m^2 + 2*m*n + n^2 - x^2 - y^2))^(1/2)/(- m^2 + 2*m*n - n^2 + x^2 + y^2));

a(4)= 2*atan((2*m*y + (- m^4 + 2*m^2*n^2 + 2*m^2*x^2 + 2*m^2*y^2 - n^4 + 2*n^2*x^2 + 2*n^2*y^2 - x^4 - 2*x^2*y^2 - y^4)^(1/2))/(m^2 + 2*m*x - n^2 + x^2 + y^2));

b(4)= -2*atan(((- m^2 + 2*m*n - n^2 + x^2 + y^2)*(m^2 + 2*m*n + n^2 - x^2 - y^2))^(1/2)/(- m^2 + 2*m*n - n^2 + x^2 + y^2));

 

以a(3)爲例,假設x=20,其它參數未知,則:

a(3)=subs(a(3),x,20) ; 便可將x取值替換爲20;

 

假設 x=20 , y=30 ,其它參數未知,則:

a(3)=subs(a(3),{x,y},{20,30});

 

二、求解矩陣方程:

a=[1 0;0 2];
b=[1;3];
syms x1 x2;
y=a*[x1;x2]+b;
s=solve(y(1),y(2),'x1','x2');
s.x1 %w2值
s.x2 %w2值


三、

Matlab求解二階微分方程組: 

m=1;
g=9.8;
k=100;
l0=1.1;
x0=[0.1 0 0 0];  %初始值; 
 
% 定義 x(1)=l, x(2)=l', x(3)=a, x(4)=a';
dx=@(t,x)[x(2); (m*x(1)*x(4)^2-m*g*cos(x(3))-k*(x(1)-l0))/m;    x(4); (-2*m*x(1)*x(2)*x(4) + m*g*x(1)*sin(x(3)))/(m*x(1)^2)];
[t,x]=ode15s(dx,[0 10],x0);

lstr = { '\itl', '{\itl}''', '\alpha', '\alpha''' };
for i=1:length(lstr)
    subplot(2,2,i)
    plot(t, x(:,i));
    xlabel('Time')
    ylabel( lstr{i} )
end
相關文章
相關標籤/搜索