Beginner Coding: Counting number of states
1 view (last 30 days)
Show older comments
Hi,
This is my first time coding with any program, and I have a "logistical" question about how to code something to count the number of states?
So the problem that I have to solve is finding the way that 5 particles can be distributed in to 0:5 energy levels given that the total energy can only be from 0-8. So what the question requires me to find is how many ways I can get one energy configuration (let's say total energy equally 4). what I've done so far is that I have made 5 loops - a=[0:5], b=[0:5], c=[0:5], d=[0:5], e=[0:5]. and so is there a function in matlab that can allow me to count how ways I can get a+ b+ c+ d+ e =4?
0 Comments
Answers (1)
Image Analyst
on 20 Mar 2015
Not a function, but just store the number
theSum = 0; % Initialize
Then your 5 for loops, and in the middle of those
if a+b+c+d+e == 4
theSum = theSum + 1;
end
0 Comments
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!