Discrepancy Between ODE45 and Solve

11 次查看(过去 30 天)
Im trying to solve a simple forced harmonic oscillators for different forcing frequencies. Solving it with Dsolve and plotting the solution returns the expected values that i found through hand calculations. Using matlab ODE 45 returns the exact same values as Dsolve but they are 10 times larger (10^-3 instead of 10^-4). I cant not figure out why there is a large discrepancy betweent the two methods. Any ideas?
Dsolve
syms x(t) w
xd = diff(x, t);
xdd = diff(xd, t);
k = 4000; m = 10; c = 200;
wn = sqrt(k/m);
ode = sin(t*w) == xdd*m + k*x +c*xd;
cond = [x(0) == 0 , xd(0) == 0];
solu = dsolve(ode, cond);
equ = simplify(solu);
t = 0:.001:5;
for w = 10:4:30
hold on
data = eval(equ);
plot(t, data,'DisplayName',num2str(w))
xlabel('Time')
ylabel('Displacement')
end
legend
ODE
function dxdt=ex1(t,x,w)
wn= 20;
z= .5;
dxdt=[x(2);1*sin(w*t)-2*z*wn*x(2)-(wn^2)*x(1)];
%%
%******ode45****Example*****************
clc; clear;
% w = 14.14;
for w = 10:4:30
options = odeset('RelTol', 1e-13, 'AbsTol', 1e-15);
[t,x]=ode45(@(t,x) HW361_7_1ODE(t,x,w), [0:.001:5] ,[0 0]);
% % % % ***************************************
hold on
% subplot(3,1,1)
plot(t,x(:,1),'DisplayName',num2str(w))
grid
xlabel('Time')
ylabel('Displacement')
legend
% %
% hold on
% subplot(3,1,2)
% plot(t,x(:,2),'DisplayName',num2str(w))
% grid
% xlabel('Time')
% ylabel('Velocity')
% legend
%
% hold on
% subplot(3,1,3)
% plot(x(:,1), x(:,2),'DisplayName',num2str(w))
% grid
% xlabel('Displacement')
% ylabel('Velocity')
% legend
end
% %*********************************
  1 个评论
Torsten
Torsten 2020-4-12
You forgot to divide sin(w*t) by a factor of 10 in the ode45 version.

请先登录,再进行评论。

回答(1 个)

James Tursa
James Tursa 2020-4-12
For dslove, the sin(w*t) signal gets divided by m, which is 10.
For ode45, you don't do this, you just have sin(w*t).
  1 个评论
Andrew Bentz
Andrew Bentz 2020-4-12
thatnk you very much,
I've been looking too much at the code and not enough at the math

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by