how to input each element (different) of a matrix 'R' in same function 'f' and compute result in the matrix form?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
- how to input each element (different) of a matrix 'R' in same function 'f' and compute result in the matrix form? *
I was trying to do this to get a series of f values in a (1x7) matrix form. Tried couple of if-loop variants, did not help. Any help is appreciated. I know this is silly, but am just very new! Thank You.
N = 7; % number of monomers % b = 1; % bond length = hypotenuse % R = rand(1, 7) f =(2 * R / (N * (b^2))) * exp(-(R^2) / (N * (b^2)))
Answers (2)
Star Strider
on 27 Feb 2015
You need to vectorise it.
See if this does what you want:
N = 7; % number of monomers %
b = 1; % bond length = hypotenuse %
R = rand(1, 7)
f =(2 * R ./ (N * (b^2))) .* exp(-(R.^2) ./ (N * (b^2)))
2 Comments
raktim roy
on 27 Feb 2015
Star Strider
on 27 Feb 2015
I don’t understand.
In your code, ‘f’ is simply a variable. It’s not a function. Your ‘R’ variable is a (1x7) vector, not a matrix.
What do you actually want to do?
Roger Stafford
on 27 Feb 2015
You need dots on the last line:
f = (2 * R / (N * b^2)) .* exp(-(R.^2) / (N * b^2))
1 Comment
raktim roy
on 27 Feb 2015
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!