4.0

4.0 | 3 ratings Rate this file 12 downloads (last 30 days) File Size: 1.77 KB File ID: #5397

hypersphere

by Gianluca Dorini

 

02 Jul 2004 (Updated 28 Mar 2005)

No BSD License  

n-dimensional hypersphere in parametric coordinates.

Download Now | Watch this File

File Information
Description

This function calculates the cartesian coordinates of an n-dimensional hypersphere given the n-1 dimensions vector 'X' of parametric coordinates and the radius 'r'

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
04 Sep 2008 fabio povoli

sei un mito !
bob

30 Mar 2009 MathMoose

Kinda slow for large dimensions due to the for loop.

Input and output are actually a matrix of column vectors, not row vectors as stated in the documentation. (matrix dimensions are usually row x column, not column x row)

Faster version ** (note this doesn't produce the exact same output as the original HyperSphere.m function, see below):
function Y = HyperSphere2(X,r=1)
% compute the cartesian coordinates from the input
% hypersphere angles and radius

% n = number of column vectors
n = size(X,2);

% cosine terms
C = [cos(X); ones(1,n)];
% sine terms
S = [ones(1,n); cumprod(sin(X),1)];
% calculate output
Y = r * C .* S;

=========
This version produces the same output as the original HyperSphere
.m (swapping the sines and cosines, and change the order of the vectors)
function Y = HyperSphere2(X,r=1)
% compute the cartesian coordinates from the input
% hypersphere angles and radius

% dimension of the input vectors
m = size(X,1);
% number of input vectors
n = size(X,2);

% reverse the order of X
X = X(m:-1:1,:);

% sine terms
S = [sin(X); ones(1,n)];
% cosine terms
C = [ones(1,n); cumprod(cos(X),1)];
% calculate output
Y = r * C .* S;

% reverse the order of Y
Y = Y(m+1:-1:1,:);

30 Mar 2009 MathMoose  
Please login to add a comment or rating.
Updates
08 Jul 2004

add screenshot

28 Mar 2005

the radius was ignored. Thanks shirley!

Tag Activity for this File
Tag Applied By Date/Time
hypersphere Gianluca Dorini 22 Oct 2008 07:26:17
parametric Gianluca Dorini 22 Oct 2008 07:26:17
radius Gianluca Dorini 22 Oct 2008 07:26:17
cartesian Gianluca Dorini 22 Oct 2008 07:26:17
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com