anderkve / FYS3150

https://anderkve.github.io/FYS3150
26 stars 14 forks source link

Weird results for relative errors for RK4 #71

Closed ivarlon closed 1 year ago

ivarlon commented 1 year ago

On problem 8 when looking at the relative errors for each $n_k$ for RK4 and FE, I get a kind of silly plot for RK4, with the relative errors not changing much for each $n_k$:

RK4

So I get a smaller convergence rate for RK4 than for FE (0.07 vs 1.4), because the maximum deviations $\Delta_{max,k}$ stay around 1e-5 for RK4, but for FE they decrease more significantly. This doesn't sound like how it should be?

anderkve commented 1 year ago

Hi @ivarlon!

Indeed, this doesn't look as expected for the RK4... If you share a link to your repo we may have time tomorrow to take a quick look at your RK4 code (no guarantees, though).

One thing to check: if you are evaluating the analytical solution in your Python plotting script, rather than in your C++ simulation code, make sure that the exact timesteps match between the two codes, i.e. that you are comparing the two solutions at exactly the same times.

If you can't figure out the problem in time, I'd advice you to write a short discussion in your report about what you suspect the problem might be, and what you would expect this plot to look like if everything was working as it should.

ivarlon commented 1 year ago

I just figured it out, and it's because I forgot a little about project 1... I didn't have enough precision in the output xD. So it works much better now that I changed output precision from 6 to 10 digits. And even better with 14 digits. Still, is it weird that I get a convergence rate for FE bigger than 1?

anderkve commented 1 year ago

Still, is it weird that I get a convergence rate for FE bigger than 1?

No, it's not surprising. We haven't discussed it much in the lectures, but the theoretically expected convergence rate is technically what you expect in the limit $h \rightarrow 0$. Before you get sufficiently close to that limit you will in general see a different convergence rate.

If you have time, you may check if your data points indicate a trend towards a convergence rate of 1 as the stepsize $h$ decreases. Note that the expression for the convergence rate is just an averaging of the slopes between our four points in a log-log plot. So an easy way to illustrate/check this is to plot the four points in a log-log plot, along with a line of slope 1. (Keep in mind that you are just comparing the slopes here -- there will be some arbitrary offset between the two graphs, so you can shift around your slope-1 line as you want to make the plot look nice.)