ODE solver with time-dependent term
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hossein192003
el 18 de Sept. de 2017
Comentada: Jan
el 21 de Sept. de 2017
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 comentarios
Respuesta aceptada
Jan
el 18 de Sept. de 2017
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 comentarios
Jan
el 21 de Sept. de 2017
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!