Discrepancy Between ODE45 and Solve

조회 수: 11 (최근 30일)
Andrew Bentz
Andrew Bentz 2020년 4월 12일
댓글: Andrew Bentz 2020년 4월 12일
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