MATLAB Answers

how to implementing energy function?

24 views (last 30 days)
Mehul Jain
Mehul Jain on 9 Apr 2020
Commented: Mehul Jain on 12 Apr 2020
i want to implement this above energy function and i tried this following code, but i am getting 'Index exceeds matrix dimensions.' error. How can do this?
for x=1:17
for y=1:19
for z=1:18
e = e + (V(x,y,z))^2;

Accepted Answer

Ameer Hamza
Ameer Hamza on 9 Apr 2020
Edited: Ameer Hamza on 9 Apr 2020
For loop is not needed. Use can use vectorized operation
Sum = sum(V.^2, 'all');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by