How do I properly use sum to sum up microstates?
11 views (last 30 days)
Show older comments
Hey, I'm trying to use a function to sum up the microstates in an evenly split two configuration system but can't get my code to work. Here's what I have:
function sumW = microstateSum(N)
n1 = N:0;
n2 = 0:N;
sumW = sum(factorial(N)/(factorial(n1)*factorial(n2)));
I'm getting an error on line 5, the last line, with * telling me that matrix dimension must agree. I just want the n1 and n2 variables to decrement and increment respectively but not interpret it as matrix multiplication. I was working with a for loop but couldn't get that to work either. New to Matlab.
0 Comments
Accepted Answer
Walter Roberson
on 1 Dec 2013
N:0 is length 0.
N:-1:0 would be length N+1
After that change the / to ./ and change the * to .*
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!