does anyone have the "leap frog" algorithm matlab script?plz help i need it!

22 views (last 30 days)
leap frog matlab script or matlab code is what i need

Answers (3)

Walter Roberson
Walter Roberson on 14 Dec 2013
Google can find SFLA MATLAB code. I have no idea of the quality of it, and I have no idea whether it is legitimate code or will delete everything on your hard disk.
I would keep in mind that if you are doing an assignment or project, that you cannot copy someone else's code.
  4 Comments

Sign in to comment.


T S Singh
T S Singh on 5 May 2016
Edited: T S Singh on 5 May 2016
You can try the following code. Its an application of Leap Frog Algorithm applied to Simple harmonic Motion
close all
clear all
clc
x(1) = 0.0; % initial position
v(1) = 2.0; % initial velocity
del_t = 0.2; % time increment
k = 0.1; % spring constant
m = 1.0; % mass
Tf = 100.0; % Final time
t = 0:del_t:Tf;
N = length(t);
v_hlf(1)=v(1)+(0.5*del_t*(-k/m)*x(1));
for j=2:N
x(j)=x(j-1)+v_hlf(j-1)*del_t;
v(j)=v_hlf(j-1)+0.5*(del_t*(-k/m)*x(j));
v_hlf(j)=v(j-1)+0.5*(del_t*(-k/m)*x(j));
end
figure; plot(t, x);
grid on;

João Socorro Pinheiro Ferreira João Ferreira
resolver:
O arquivo-m advection\_LW\_pbc.m implementa o método Lax-Wendroff para a equação advecção em $0 \leq x \leq 1$ com condições de contorno periódicas.
\begin{itemize}
\item [(a)] Modifique o arquivo.m para criar uma versão advection\_lf\_pbc.m implementando o leapfrog e verifique se isso é preciso de segunda ordem. Observe que você terá que especificar dois níveis de dados iniciais. Para o conjunto de teste de convergência $U_j^1 = u (x_j, k)$, a solução verdadeira em tempo $k$.
\item [(b)] Modifique advection\_lf\_pbc.m para que os dados iniciais consistam em um pacote de ondas
\begin{equation}
\eta (x) = \exp{(-\beta (x - 0.5)^2}\sin{(\xi x)} \hspace{1.5cm} (Ex. 10.9a)
\label{011121b}
\end{equation}
Descubra a verdadeira solução $u (x, t)$ para esses dados. Usando $\beta = 100$, $\xi = 80$ e $U_j^1 = u (x, k)$, teste se seu código ainda exibe uma precisão de segunda ordem para $k$ e $h$ suficientemente pequena.
\item [(c)] Usando $\beta = 100$, $\xi = 150$ e $U_j^1 = u (x_j, k)$, estime a velocidade do grupo do pacote de onda
calculado com leapfrog usando $m = 199$ e $k = 0.4h$. Quão bem isso se compara com o valor (10.52) predito pela equação modificada?
\end{itemize}
  1 Comment
Steven Lord
Steven Lord on 24 Nov 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!