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 comentario

Torsten
Torsten el 12 de Abr. de 2020
You forgot to divide sin(w*t) by a factor of 10 in the ode45 version.

Iniciar sesión para comentar.

Respuestas (1)

James Tursa
James Tursa el 12 de Abr. de 2020

0 votos

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 comentario

Andrew Bentz
Andrew Bentz el 12 de Abr. de 2020
thatnk you very much,
I've been looking too much at the code and not enough at the math

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 12 de Abr. de 2020

Comentada:

el 12 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by