Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help creating the for loop calling the vanderWaals function in MATLAB. Func

ID: 3833576 • Letter: N

Question

Need help creating the for loop calling the vanderWaals function in MATLAB.

Function vanDerWaalsForces.m Purpose Compute the van der Waals energy and forces for Argon atoms Input x a vector of x-coordinates (Angstroms) y a vector of y-coordinates (Angstroms) Output energy the potential energy (Kcal/mole) N fx the x-component of the force (Kcal/mole/Angstrom) the force (Kcal/mole/Angstrom) of the y-component function Cenergy, fx, fy] vander Waals(x, y) eps4 0.2824. 4.0 rmln 3.361 rmin6 rminA6 rmin12 rminA12 nAtoms length(x) Zero out energy energy 0; Zero out forces fx zeros (1, nAtoms) fy zeros (1, nAtoms) Loop over atoms to accumulate energy and forces for i 1:nAtoms x(i) Xl yi y(i) Loop over atoms whose index is greater than i for j i+1:nAtoms Compute separation distance (Angstroms) dx x(j) Xl. dy y(j) r sqrt (dx dx dy dy) Compute interaction energy ir 1.0/r ir6 irA6 ir12 ir 6 ir 6 e 3 eps4 ir 12 rmin6*ir6) energy energy e; Compute equal and opposite forces includeing chain rule term ir7 ir ir ir13 ir12 ir de eps4* (6.0*rmin6 r7 12.0 rmin 12 ir 13) dxr de dx/r dyr 3 de dy/r fx(i) fx (i) dxr fy(i) fy(i) dyr fx(j) fx (j) d fy(j) fy (j) dyr end end end

Explanation / Answer

CODE:

Since your code was in image format, I could not copy it to test the below code.
But it should work.

energy = []
fx=[];
fy=[];

for i=1:5000
[energy(i),fx(i),fy(i)] = vanderWaals(x,y);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote