ODE solver with time-dependent term
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Jan
2017-9-18
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
2 个评论
Jan
2017-9-21
I do not understand the question. Do you want to display sicw or its integral? For the first, you have the formula already, for the second, insert it in the function to be integrated and let ODE45 integrate it. Or use intergral (quad in older Matlab versions).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!