http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745
MATLAB Central Newsreader  Summation
Feed for thread: Summation
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 06 Aug 2010 22:45:05 +0000
Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769356
Mohammad
Dear reader,<br>
<br>
I have a vector with r entries which are imputed previously. I want to PLOT a function v(x), such that v=@x Star(1,1)*sin(pi*x)+Star(1,2)*sin(2*pi*x)+Star(1,3)*sin(3*pi*x)+....Star(1,n)*sin(n*pi*x)+...Star(1,r1)*sin((r1)*pi*x)+Star(1,r)*sin(r*pi*x)<br>
<br>
Is there a simple way to do this using matrix summation.<br>
<br>
(P.S. I only need to plot it, so if there is a way to not need to create a function, I'll take it)<br>
<br>
This is what I though of so far:<br>
Yarr=ones(r,200)<br>
for i = 1:r<br>
for x = 1:200<br>
Yarr(i,x)=Star(1,i)*sin(i*pi*x)<br>
end<br>
end

Sat, 07 Aug 2010 16:59:04 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769430
Matt J
"Mohammad " <jaber2@uni.uiuc.edu> wrote in message <i3i39h$44i$1@fred.mathworks.com>...<br>
> Dear reader,<br>
> <br>
> I have a vector with r entries which are imputed previously. I want to PLOT a function v(x), such that v=@x Star(1,1)*sin(pi*x)+Star(1,2)*sin(2*pi*x)+Star(1,3)*sin(3*pi*x)+....Star(1,n)*sin(n*pi*x)+...Star(1,r1)*sin((r1)*pi*x)+Star(1,r)*sin(r*pi*x)<br>
=================<br>
<br>
v=@(x) sum( Star.*sin( pi*x(:)*(1:r) ) ,2 );<br>
plot(1:200,v(1:200));

Sat, 07 Aug 2010 17:17:04 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769434
Matt J
"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3k3co$ldr$1@fred.mathworks.com>...<br>
<br>
> <br>
> v=@(x) sum( bsxfun(@times, sin( pi*x(:)*(1:r) ) , 2 );<br>
> plot(1:200,v(1:200));<br>
==============<br>
<br>
Sorry, make that<br>
<br>
v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';<br>
<br>
plot(1:200,v(1:200));

Sat, 07 Aug 2010 17:45:04 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769438
Roger Stafford
"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3k4eg$qp0$1@fred.mathworks.com>...<br>
\> v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';<br>
          <br>
You don't need bsxfun for this one:<br>
<br>
v = @(x) sin(pi*x(:)*(1:r))*Star.';<br>
<br>
Roger Stafford

Sat, 07 Aug 2010 18:54:03 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769448
Mohammad
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i3k630$8dp$1@fred.mathworks.com>...<br>
> "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3k4eg$qp0$1@fred.mathworks.com>...<br>
> \> v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';<br>
>           <br>
> You don't need bsxfun for this one:<br>
> <br>
> v = @(x) sin(pi*x(:)*(1:r))*Star.';<br>
> <br>
> Roger Stafford<br>
<br>
Thanks everyone. Just for educational purpose (So I can do this in the future) does the x(:) mean that x is changing, and what does the .' after Star signify.<br>
<br>
THANKS! this made my program a whole lot simpler.<br>
<br>
Cordially, Mohammad

Sat, 07 Aug 2010 20:48:04 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769460
Matt Fig
"Mohammad " <jaber2@uni.uiuc.edu> wrote in message <br>
> Thanks everyone. Just for educational purpose (So I can do this in the future) does the x(:) mean that x is changing, and what does the .' after Star signify.<br>
> <br>
> THANKS! this made my program a whole lot simpler.<br>
> <br>
> Cordially, Mohammad<br>
<br>
Look<br>
<br>
doc colon<br>
doc transpose

Sat, 07 Aug 2010 20:57:03 +0000
Re: Summation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288745#769462
Roger Stafford
"Mohammad " <jaber2@uni.uiuc.edu> wrote in message <i3ka4b$cd0$1@fred.mathworks.com>...<br>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i3k630$8dp$1@fred.mathworks.com>...<br>
> > "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3k4eg$qp0$1@fred.mathworks.com>...<br>
> > \> v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';<br>
> >           <br>
> > You don't need bsxfun for this one:<br>
> > <br>
> > v = @(x) sin(pi*x(:)*(1:r))*Star.';<br>
> > <br>
> > Roger Stafford<br>
> <br>
> Thanks everyone. Just for educational purpose (So I can do this in the future) does the x(:) mean that x is changing, and what does the .' after Star signify.<br>
> <br>
> THANKS! this made my program a whole lot simpler.<br>
> <br>
> Cordially, Mohammad<br>
        <br>
No, x(:) makes a column vector out of the elements of x just in case your x was a row vector. (Actually it will make a column vector out of a matrix too.) The .' after Star takes its transpose. This is necessary so that the number of columns in sin(pi*x(:)*(1:r)) will equal the number of rows in Star.' and yield a valid matrix multiplication with the * operation in between them. You should read up in your matlab manual about indexing and matrix multiplication. It's an important part of one's matlab education.<br>
<br>
Roger Stafford