📄 odesys.m
字号:
% File ODEsys for finding numerical and exact solutions
% to the system of differential equations
% y1'=-30*y1-29*y2; y2'=-29*y1-30*y2 with the initial conditions
% y1(0) = 2, y2(0) = 0.
% Symbolic Math Toolbox must be installed.
f = inline('-[30 29;29 30]*y','t','y');
[t,y] = ode45(f,[0 1],[2 0]);
plot(t,y(:,1),t,y(:,2),'--')
legend('y1','y2')
title('Numerical solutions y_1 and y_2')
xlabel('t')
pause (5)
figure
[y1,y2] = dsolve('Dy1=-30*y1-29*y2','Dy2=-29*y1-30*y2',...
'y1(0)=2','y2(0)=0')
exact = [subs(y1,t) subs(y2,t)];
plot(t,y(:,1)-exact(:,1),'-',t,y(:,2)-exact(:,2),'--')
legend('e1','e2')
title('Errors e_1 = y_1- exact y_1 and e_2 = y_2 - exact y_2')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -