From: Mohammad on
Dear reader,

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,r-1)*sin((r-1)*pi*x)+Star(1,r)*sin(r*pi*x)

Is there a simple way to do this using matrix summation.

(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)

This is what I though of so far:
Yarr=ones(r,200)
for i = 1:r
for x = 1:200
Yarr(i,x)=Star(1,i)*sin(i*pi*x)
end
end
From: Matt J on
"Mohammad " <jaber2(a)uni.uiuc.edu> wrote in message <i3i39h$44i$1(a)fred.mathworks.com>...
> Dear reader,
>
> 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,r-1)*sin((r-1)*pi*x)+Star(1,r)*sin(r*pi*x)
=================

v=@(x) sum( Star.*sin( pi*x(:)*(1:r) ) ,2 );
plot(1:200,v(1:200));
From: Matt J on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3k3co$ldr$1(a)fred.mathworks.com>...

>
> v=@(x) sum( bsxfun(@times, sin( pi*x(:)*(1:r) ) , 2 );
> plot(1:200,v(1:200));
==============

Sorry, make that

v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';

plot(1:200,v(1:200));
From: Roger Stafford on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3k4eg$qp0$1(a)fred.mathworks.com>...
\> v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';
- - - - - - - - - - -
You don't need bsxfun for this one:

v = @(x) sin(pi*x(:)*(1:r))*Star.';

Roger Stafford
From: Mohammad on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i3k630$8dp$1(a)fred.mathworks.com>...
> "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3k4eg$qp0$1(a)fred.mathworks.com>...
> \> v=@(x) sum( bsxfun( @times, sin( pi*x(:)*(1:r) ),Star) , 2 ).';
> - - - - - - - - - - -
> You don't need bsxfun for this one:
>
> v = @(x) sin(pi*x(:)*(1:r))*Star.';
>
> Roger Stafford

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.

THANKS! this made my program a whole lot simpler.

Cordially, Mohammad