MatLab: array of numbers unequal distribution

In summary, the conversation is about creating an array of numbers between 0 and 0.1, with the points clustered around an arbitrary point x1. The points should get exponentially closer together near x1 and further apart towards the outer limits. The conversation mentions using MatLab and trying to use tanh and linspace. An alternative method using logspace is also mentioned. The conversation also discusses the possibility of assigning different values to each point and calculating the weighted mean of the entire line. The formula for weighted mean is provided and additional resources are suggested for further understanding.
  • #1
AnneElizabeth
19
0
I want to create an array of numbers between 0 and 0.1 where the points are clustered around an arbitrary point x1 (0 < x1 < 0.1). I want the points to get exponentially closer together near x1 from either side and and get further apart towards the outer limits. I am using MatLab and was trying to use tanh and linspace.
tanh(linspace(0,6,50)) gives a suitable shape for 0 to x1 and -tanh(linspace(1,6,50)) for x1 to x2.
However I can't make it work for my limits, taking into account that x1 varies.

(I will later need to take a weighted mean of these points but that's another problem..)
 
Physics news on Phys.org
  • #2
Something like this perhaps:

Code:
function y = clusteredNumbers(N,x1)
% Generates 2*N numbers from 0 to 0.1, with N numbers on each side of x1.
% The numbers cluster about the point x1.
x0 = linspace(0,6,N);
z = x1*tanh(x0);
z1 = 0.1 - fliplr((0.1-x1)*tanh(x0));
y = [z'; z1'];
end

For x1 = 0.03 and N = 50, this produces the attached plot.

Code:
y = clusteredNumbers(50, 0.03);
plot(y,ones(100,1),'.')

EDIT: An alternative to using linspace + tanh is to use logspace, which is similar to linspace but produces logarithmically spaced values.
 

Attachments

  • clustered_nums.png
    clustered_nums.png
    2.3 KB · Views: 752
  • Like
Likes AnneElizabeth
  • #3
kreil said:
Something like this perhaps:

Code:
function y = clusteredNumbers(N,x1)
% Generates 2*N numbers from 0 to 0.1, with N numbers on each side of x1.
% The numbers cluster about the point x1.
x0 = linspace(0,6,N);
z = x1*tanh(x0);
z1 = 0.1 - fliplr((0.1-x1)*tanh(x0));
y = [z'; z1'];
end

For x1 = 0.03 and N = 50, this produces the attached plot.

Code:
y = clusteredNumbers(50, 0.03);
plot(y,ones(100,1),'.')

EDIT: An alternative to using linspace + tanh is to use logspace, which is similar to linspace but produces logarithmically spaced values.
Thank you! That's exactly what I wanted!
If each of those points have a different value, any chance you know how to calculate the weighted mean of the whole line? Can't figure it out with the spacing between the points.
 
  • #4
Not sure I follow... Are these random numbers the weights you want to use for the associated values? If so you just dot product them together and divide by the number of elements.
 
  • #5
I mean if I assign a y-value to each of those points, how would I calculate the mean of all the points, as if I just used the simple formula for mean of: (sum of the y-values)/(number of points) it wouldn't take into account that the points are unequally spaced.
xyvals.jpg
 
  • #6

What is MatLab and how is it used?

MatLab is a high-level programming language and interactive environment used for numerical computation, visualization, and data analysis. It is commonly used in fields such as mathematics, engineering, and science for tasks such as data manipulation, statistical analysis, and creating graphical representations of data.

What is an array of numbers in MatLab?

In MatLab, an array of numbers is a collection of values or elements arranged in a specific order. This can be a single row or column of numbers, or a multi-dimensional array with multiple rows and columns. Arrays can be used to store and manipulate data, perform calculations, and create visualizations.

What does "unequal distribution" mean in relation to an array of numbers in MatLab?

An unequal distribution of numbers in MatLab means that the elements in the array are not evenly spaced or distributed. This can occur when the values in the array have different frequencies or are not evenly distributed along the range of values.

How can I create an array of numbers with an unequal distribution in MatLab?

To create an array of numbers with an unequal distribution in MatLab, you can use the rand or randn functions. These functions generate random numbers with a uniform or normal distribution, respectively. You can then manipulate the generated array to create an unequal distribution by changing the range or frequency of values.

What are some common methods for analyzing an array of numbers with an unequal distribution in MatLab?

Some common methods for analyzing an array of numbers with an unequal distribution in MatLab include statistical measures such as mean, median, and standard deviation to understand the central tendency and spread of the data. You can also use visualization techniques, such as histograms or box plots, to explore the distribution of the data and identify any outliers or patterns.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
13
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top