Discrepancy Between ODE45 and Solve

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 日

0 投票

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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2019b

タグ

質問済み:

2020 年 4 月 12 日

コメント済み:

2020 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by