MATLAB: ODE solver with time-dependent term

ode solvertime-dependent terms in ode

Do MATLAB ODE solvers usually change the _ * time-dependent terms*_ in the Ordinary differential set of equations? As a simple example, consider the following example from [ 1 ]
function xdot = fun1(t,x,beta,omega,A,w0,theta)
% The time-dependent term is A * sin(w0 * t - theta)
sicw=A * sin(w0 * t - theta);
xdot(2)= -beta*x(2) + omega^2 * x(1) + sicw;
xdot(1) = x(2);
xdot=[xdot(:);sicw];
% To make xdot a column
% End of FUN1.M
end
Where calling the function as follow:
beta = .1;
omega = 2;
A = .1;
w0 = 1.3;
theta = pi/4;
X0 = [0 1 0]';
t0 = 0;
tf = 20;
options = [];
[t,y]=ode23(@fun1,[t0,tf],X0,options,beta,omega,A,w0,theta);
When I try to plot the time-dependent term,
sicw=A * sin(w0 * t - theta);
Outside the function or as the third column of the output "y" output versus "t", I get different graphs:
In this example, at least the overall behavior of the graph is preserved, However in my actual code, where the time-dependent term is again a sinusoid,
sicw=0.05e9*sin(2*pi*t/(10e-9))+0.05e9;
the output is worse and even the behavior is not the same!
I don't really know what is going on! Any help is appreciated.

Best Answer

Outside the function or as the third column of the output "y" output versus "t", I get
different graphs: ...
Of course you do. Inside the function to be integrated you define get the value:
sicw = A * sin(w0 * t - theta);
and provide it as 3rd component. Then ODE45 integrates this. This must be different from the values defined outside the integration
sicw = A * sin(w0 * t - theta);
because ODE45 replies its integral:
Integral(a * sin(b*t)) = -a/b * cos(b*t) + C
Related Question