I have tried Runge Kutta method on this coupled nonlinear ode and get the error respect to the matrix dimension. Please help me with this.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% Define spatial domain
Ly = 2; % Length of domain
Lz = 1;
N = 200; % Number of discretization points
M = 200;
dy = Ly/N;
dz = Lz/M;
y = -1; % Define x domain % for fixed values of y
z = 0:dz:Lz;
[Y,Z] = meshgrid(y,z);
% Define discrete wavenumbers
eta = (2*pi/Ly)*[-N/2:N/2];
eta = fftshift(eta'); % Re-order fft wavenumbers
jeta = (2*pi/Lz)*[-M/2:M/2];
jeta = fftshift(jeta'); % Re-order fft wavenumbers
[Eta,Jeta] = meshgrid(eta,jeta);
%% Time domain %%
t(1) = 0; dt = 0.05; tf = 10; L = ceil(tf/dt)+1;
%% function handle %%
f = @(t,F,G) (-g1.*J-F.*((F).*(2.*pi.*1i.*jeta))-((nu+nu_t).*(jeta.^2+eta.^2).*4.*pi.^2)-(nu_t.*4.*pi.^2.*jeta.*eta)-(G.*2.*pi.*1i.*eta));
g = @(t,F,G) (-g1.*J.*P-G.*((G).*(2.*pi.*1i.*eta))-((nu+nu_t).*(jeta.^2+eta.^2).*4.*pi.^2)-(nu_t.*4.*pi.^2.*jeta.*eta)-(F.*2.*pi.*1i.*jeta));
%% Initial condition %%
F(1) = 0; G(1) = 0;
%% Main calculation %%
for i = 1:L+1
t(i+1) = t(i)+dt
k1F = f(t(i), F(i), G(i));
k1G = g(t(i), F(i), G(i));
k2F = f(t(i)+dt./2,F(i)+dt./2.*k1F,G(i)+dt./2.*k1G);
k2G = g(t(i)+dt./2,F(i)+dt./2.*k1F,G(i)+dt./2.*k1G);
k3F = f(t(i)+dt./2,F(i)+dt./2.*k2F,G(i)+dt./2.*k2G);
k3G = g(t(i)+dt./2,F(i)+dt./2.*k2F,G(i)+dt./2.*k2G);
k4F = f(t(i)+dt, F(i)+dt.*k3F, G(i)+dt.*k3G);
k4G = g(t(i)+dt, F(i)+dt.*k3F, G(i)+dt.*k3G);
F(i+1) = F(i) + (dt./6).*(k1F + 2.*k2F + 2.*k3F + k4F);
G(i+1) = G(i) + (dt./6).*(k1G + 2.*k2G + 2.*k3G + k4G)
end
1 commentaire
Torsten
le 6 Jan 2022
We can't check your code because several variables in the definition of f and g are undefined.
Réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!