3.5

3.5 | 2 ratings Rate this file 6 downloads (last 30 days) File Size: 1.54 KB File ID: #18526

Geometrically spaced vector

by Gus Brown

 

30 Jan 2008 (Updated 16 Apr 2008)

Code covered by the BSD License  

Create a geometrically spaced vector where each subsequent step is G times bigger than the previous

Download Now | Watch this File

File Information
Description

Matlab supplies the functions linspace and logspace to generate vectors. This is a alternate/additional spacing algorithm to add to the list.

Geometric spacing in this case is defined as points spaced in such a way that each subsequent step is G times bigger than the previous one.

GEOSPACE(X1, X2) generates a row vector of 100 linearly equally spaced points between X1 and X2.

GEOSPACE(X1, X2, N) generates N linearly spaced points between X1 and X2. If N<2 then X2 is returned.

GEOSPACE(X1, X2, N, G) generates N points between X1 and X2 with a spacing defined by G. Each step is G times bigger than the previous step.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
30 Jan 2008 Dimitri Shvorob

Supplied three inputs, the function (for some reason) replicates LINSPACE. Supplied four inputs.. how can one set both N and G? In any case, the task is a two-liner:

function[x] = geospace(x1,x2,n)
k = (x2/x1)^(1/(n-1));
x = k.^(0:(n-1))*x1;

30 Jan 2008 Gus Brown

Actually the code you submitted does not replicate the functionality of geospace. And yes it is a two-liner but I find it useful, I'm sorry you don't.

You can specify N and G as the help suggests by using the following form
GEOSPACE(X1, X2, N, G)

Note: G specifies the growth in spacing and not the initial spacing.

When you specify two inputs the default spacing growth G is 1, i.e. the same as linspace. Please read the help file.

22 Dec 2009 Matt Fig

Works as advertised.

Please login to add a comment or rating.
Updates
07 Feb 2008

Changed the summary wording to fit the 100 character limit.

11 Feb 2008

Added an example to the help.

16 Apr 2008

Description change

Tag Activity for this File
Tag Applied By Date/Time
spacing vector geometric Gus Brown 22 Oct 2008 09:45:33

Contact us at files@mathworks.com