ODE solver with time-dependent term

조회 수: 3 (최근 30일)
hossein192003
hossein192003 2017년 9월 18일
댓글: Jan 2017년 9월 21일
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.

채택된 답변

Jan
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
hossein192003
hossein192003 2017년 9월 20일
Thank you Jan for your answer. In my original code "sicw" is a time-dependent input and I want that to be a sinusoidal function of time, So do I need to define it as:
sicw = (0.05e9*2*pi/10e-9)*cos(2*pi*t/(10e-9));
Where then its integral would be my desired input? Or I do not need to change it and keep it as it is?
Thanks, Hossein
Jan
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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by