Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In numerical methods, there are often many ways to make a calculation that give the same answer but have vastly different efficiencies. In this problem,
In numerical methods, there are often many ways to make a calculation that give the same answer but have vastly different efficiencies. In this problem, we are going to consider a common calculation in molecular dynamics simulations, which requires computing the term LJ = 1/r^6 + 1/r^12 (If you are familiar with this topic, we are going to compute the Lennard-Jones potential without any prefactors.) Let us consider two particles, one located at (1, 0, 3) and another particle located at (2, -2, -1) and the following two methods for computing the LJ potential between these two particles. The input to the calculation is the positions of the two particles. Method 1 (1) Calculate r = squareroot delta x^2 + delta y^2 + delta z^2, where delta x is the distance x_1 - x_2 and so forth. (2) Calculate LJ by plugging the value of r into the formula above. Method 2 (1) Calculate r^2 = delta x^2 + delta y^2 + delta z^2. (2) Calculate 1/r^2. (3) Calculate 1/r^6 = 1/r^2 times 1/r^2 1/r^2. (4) Calculate 1/r^12 = 1/r^6 times 1/r^6. (5) Calculate LJ by adding the results from the previous two steps. Write a MATLAB program that determines the amount of time required to do Method 1 and Method 2 if you do the calculation 10, 100, ..., 10^8 times. Look at how the calculation time increases with the number of times you need to do it - in simulations, you would make this calculation an enormous number of times. For these calculations, you should use the tic and toc commands in MATLAB to get the time. Your program should automatically produce a log-log plot of the time required versus the number of calculations
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started