No BSD License  

Highlights from
hypersphere

4.0

4.0 | 3 ratings Rate this file 1 Download (last 30 days) File Size: 1.77 KB File ID: #5397
image thumbnail

hypersphere

by Gianluca Dorini

 

02 Jul 2004 (Updated 28 Mar 2005)

n-dimensional hypersphere in parametric coordinates.

| 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

Contact us at files@mathworks.com