how to input each element (different) of a matrix 'R' in same function 'f' and compute result in the matrix form?

  • 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)

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

well thats useful concept. but doesn't help me use each of the element in R as an input in the function f, and collect the results for each in a matrix form. I want to do that.
Thanks though.
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?
You need dots on the last line:
f = (2 * R / (N * b^2)) .* exp(-(R.^2) / (N * b^2))

This question is closed.

Asked:

on 26 Feb 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!