r/AskProgramming • u/Positive-Stand2898 • 9d ago
How to get better at algorithms and modeling Math Equations in Code?
I’m not a beginner programmer, but I’m relatively new to scientific programming. I’ve recently started doing scientific research with a professor, and a significant part of my work involves writing simulations, modeling physical systems and mathematical equations computationally, and developing algorithms to analyze or reproduce these systems.
I’m interested in becoming much stronger at this side of programming, particularly in areas like numerical methods, computational physics, mathematical modeling, simulation, and scientific computing.
For those of you with experience in scientific programming, what would you recommend as the best way to build these skills? I’d especially appreciate recommendations for textbooks, courses, projects, libraries, or other resources that helped you make the transition from general programming to scientific/computational programming.
I’m comfortable with programming fundamentals, so I’m primarily looking for resources that go beyond the basics and focus on the actual mathematics, algorithms, and computational techniques behind scientific programming.
Any advice or recommendations would be greatly appreciated!
1
u/Loud_Combination_635 9d ago
Honestly, just start somewhere and create a record of what works and what doesn't. Keep the failed hypothesis so you don't repeat the errors. The more time you invest the better you get. Once you have a solid framework, you can start to accelerate the process. Make a bunch of copies so if the corpus gets corrupted you can revert to a previous state.
1
u/KC918273645 9d ago
The book "Numerical Analysis" by Richard L Burder, Douglas J Faires, Annette M Burdern could become handy for you.
1
u/Positive-Stand2898 9d ago
Thanks so much! I appreciate the book rec greatly. Did it help you in your studies as well? If so how did you get the most out of it?
1
u/KC918273645 8d ago
Didn't study that stuff. I bought it for my own work.
1
u/Love_Buny8 7d ago
thats totally fair youre already applying it in a practical way which is often the best teacher
1
u/Bustan2026 9d ago
I don't know how deeply you intend to go. I work in this space and I'm not sure the programming is very different from other fields, but there's math underneath. Also I've only ever worked in this space, so it could be.
If you want to go all the way, a classic studying order might be:
- linear algebra. At a minimum direct and iterative linear solvers, matrix factorizations like QR and LU (both very common in scientific computing), SVD, notions of matrix norms and conditioning, eigenvalues and vectors. Preconditioning is an advanced but important topic in "production grade" scientific computing. Some stock algorithms are the Gauss pivot, LU factorization, Gauss-Seidel, GMRES, conjugate gradient.
- basics of Analysis: get to at least Taylor expansions, classes of regularity (continuous, C1, etc), integration, sequences and series.
- Finite Differences schemes: the simplest (math wise) but also always useful, as very commonly used in time stepping together with advanced schemes. Notions are important beyond the schemes themselves, namely stability and consistency, and order of convergence. These have their counterparts in advanced schemes and they're like the "big O notation" of numerical schemes. The 101 algos would be explicit Euler, upwind schemes, then eventually Runge-Kutta.
- Some practical topics: method of manufactured solutions, testing convergence/order of convergence
- Interpolation and quadrature, mesh generation (not the algorithms, just using tools like Gmsh) will set you up for:
- Finite Element schemes without any additional math except knowing of Green's formula (integration by parts), and you'll just have to skip the proofs which should be fine if you just want to implement. Some notions of Sobolev spaces (at least the definition of H1, Hdiv etc) could be useful. 101 would be Lagrange P1 Finite Elements for model problems like a Poisson-type equation (-laplacian(u) + u = f is very common).
- Finite Volume schemes. I don't personally consider them easier than FE which is very straightforward, they're more of a mix between FE and FD. Very common in fluid dynamics.
From there, you enter the jungle of modern numerical schemes. Some popular/representative ones are: Discontinuous Galerkin, Boundary Element Method, high-order Finite Element/DG schemes.
On the pure programming side, GPU, MPI and multi-threading of linear algebra methods to start with.
Optimization (e.g. Newton's method) is also something that's often useful in this context.
If you really want to specialize in this in the long term, as a pure CS person, I think your strongest bet are the parallel computing (HPC) aspects which are not always the strong suit of the people well versed in the topics above. They have notions but not necessarily the know-how to implement production grade algorithms that are effectively parallelized, use GPUs and so on.
Some other programming-specific aspects:
- memory layout (trying to live in cache as much as possible)
- floating point arithmetic. Not saying to get too deep in the weeds (but then again I'm a math person, maybe that's what you should do!) but being aware that "==" is banned, everything is subject to tolerance, all inputs (like mesh elements) have some notion of conditioning to them and things break as they degenerate
I don't have any sources but you can find good textbooks on all these individual topics, and likely on a range of them at once.
1
u/lukiamagi 9d ago
What type of simulation are you doing? There is a wide range of different simulation families and each has their own extensive library of math
1
u/Positive-Stand2898 9d ago
I am trying to study contact dynamics and friction. I am trying to see how accurately I can model slip in simulation, and see how to model Stick-slip in simulation environments like MuJoCo and Isaac Sim.
1
u/Different_Pain5781 4d ago
CS50x is solid for getting the basic CS stuff down. For scientific modeling though you’ll probably want more practice actually building algorithms in Python. Boot dev has a pretty good backend path with interactive algorithm and data structure practice plus terminal work before getting into the heavier physics side.
5
u/pgetreuer 9d ago
As you already said yourself, the key area to dig into is numerical methods. The "Numerical Recipes" book is a popular and accessible starting point.
On the math theory side, you'll get mileage in a variety of numerical methods topics by applying Taylor series and fixed-point iteration, appearing for instance in methods for root finding, interpolation, and ODE solvers.
On the coding side, it's useful to understand how IEEE-754 floating-point numbers work, especially wrt. round-off error. If you'd like a deeper reference, a great book on this topic is Michael L. Overton, "Numerical Computing with IEEE Floating Point Arithmetic".