Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Speeding up calculation of matrix
Replies: 5   Last Post: Mar 27, 2012 11:21 AM

 Messages: [ Previous | Next ]
 Michael Posts: 4 Registered: 3/26/12
Re: Speeding up calculation of matrix
Posted: Mar 27, 2012 9:43 AM

"Roger Stafford" wrote in message <jkql7d\$5r1\$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jkqh5t\$ka3\$1@newscl01ah.mathworks.com>...
> > [py,px] = ndgrid(0:fit_y,0:fit_x);
> > M = bsxfun(@power,x,reshape(px,1,[]))+bsxfun(@power,y,reshape(py,1,[]));

> - - - - - - - - - -
> As a third alternative you could try this to minimize the total number of power operations (70 vs 240):
>
> n = size(x,1);
> M = reshape(bsxfun(@plus,bsxfun(@power,y,0:fit_y), ...
> reshape(bsxfun(@power,x,0:fit_x),n,1,[])) ,n,[]);
>
> Roger Stafford

Thanks Roger - I am getting about a 30% reduction in run time using this method (after replacing the first function call to @times instead of @plus). Exactly the kind of solution I was looking for. The solution using ndgrid ran a bit slower - the ndgrid call took a while to compute.

Thanks again,
Michael

Date Subject Author
3/26/12 Michael
3/26/12 Roger Stafford
3/26/12 Roger Stafford
3/26/12 Roger Stafford
3/27/12 Michael
3/27/12 Roger Stafford