Borrar filtros
Borrar filtros

how to interpolate the data over uniform time grid

8 visualizaciones (últimos 30 días)
PetronasAMG
PetronasAMG el 26 de Sept. de 2021
Respondida: Nipun el 30 de Mayo de 2024
Since numerical solution obtained from ode45 is a non uniform in time, I need to obtain the frequency power spectrim of the solution, but first, i need to interpolate the date over unifrom time grid. How would i able to do so? I am completely stuck after inputting vlause from ODE45! Please explain the steps!
function dxdt = frs(t,x)
dxdt = zeros(3,1);
dx1dt = -((4/5)*x(2)+x(1));
dx2dt = x(3) + ((4/9)*x(2));
dx3dt = (1/8)+((x(1)-2.5)*x(2));
end
tspan = [0:10:100];
xi = [1.0;4.0;2.0];
[t,x]= ode45(@frs,tspan,xi);
from here I do not know how to process with the question please help!
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Sept. de 2021
Since numerical solution obtained from ode45 is a non uniform in time
That is only the case if you pass in a two-element tspan. When you pass in a tspan that is uniform in time, the way you do, then the output from ode45 will only be at those times, and so the output would be uniform in time.
Mathieu NOE
Mathieu NOE el 27 de Sept. de 2021
you can also interpolate the output data of your ode solution over a new time vector (linear)
use interp1
maybe this will be faster than forcing ode to work on fixed , refined time vector

Iniciar sesión para comentar.

Respuestas (1)

Nipun
Nipun el 30 de Mayo de 2024
Hi [First Name]
I understand that you want to interpolate data over a uniform time grid. Here’s how you can do it using interp1 in MATLAB:
% Given data
time = [0, 1, 4, 5, 6]; % Non-uniform time points
data = [10, 20, 15, 25, 30]; % Corresponding data points
% Uniform time grid
uniformTime = linspace(min(time), max(time), 100);
% Interpolate data over uniform time grid
uniformData = interp1(time, data, uniformTime, 'linear');
% Display results
plot(time, data, 'o', uniformTime, uniformData, '-');
xlabel('Time');
ylabel('Data');
legend('Original Data', 'Interpolated Data');
For more details on interpolation, refer to the MathWorks documentation on interp1: https://www.mathworks.com/help/matlab/ref/interp1.html
Hope this helps.
Regards,
Nipun

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by