Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: sum of exponentials
Replies: 9   Last Post: Nov 24, 2012 7:16 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dwi

Posts: 17
Registered: 10/18/12
Re: sum of exponentials
Posted: Nov 24, 2012 9:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Roger Stafford" wrote in message <k8onag$2kt$1@newscl01ah.mathworks.com>...
> "dwi" wrote in message <k8o3vo$ia$1@newscl01ah.mathworks.com>...
> > A correction:
> > x8=(x7*e^(-1))/e^(-1)
> > ie without using x1,x2,x3 but only the immediate previous non-zero values

> - - - - - - - - -
> With the correction you made, here is my modified code:
>
> % An example:
> x = [12,17,21,0,0,0,31,0,0];
> e = exp(1); % <-- I assume this is what 'e' is
>
> % The code:
> a = 0; b = 1; f = 0;
> for k = 1:length(x)
> if x(k) ~= 0
> a = x(k) + a*f*e^(-1);
> b = 1 + b*f*e^(-1);
> f = 1;
> else
> x(k) = a/b;
> f = 0;
> end
> end
>
> % The results:
>
> [(x(3)+x(2)*e^(-1)+x(1)*e^(-2))/(1+e^(-1)+e^(-2));
> x(4);
> x(5);
> x(6)] =
>
> 19.21081095724738
> 19.21081095724738
> 19.21081095724738
> 19.21081095724738
>
> [x(7);
> x(8);
> x(9)] =
>
> 31
> 31
> 31
>

> > Thank you for your answer but if I use this the index of the exponent never changes.I want it to decrease as k increases, and i don't know hot to calculate a sum like this.
>
> In the earlier thread where you said, "but if I use this the index of the exponent never changes", I don't know what you meant, but that code was doing just what you had asked for at that time.
>
> Roger Stafford


Ok, I understand now how this works. But still, you said the result will be
x(3)+x(2)*e^(-1)+x(1)*e^(-2))/(1+e^(-1)+e^(-2));
while I want
(x(3)*e^(-1)+x(2)*e^(-2)+x(1)*e^(-3))/(e^(-1)+e^(-2)+e^(-3));
Also, how would your code change if I had e^(-1/20), e^(-2/20), e^(-3/20) etc?
Thank you for your time.This has been extremely helpful!



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.