Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
can you help me find the mistake here

Subject: can you help me find the mistake here

From: salamay

Date: 14 Oct, 2010 19:16:03

Message: 1 of 4

In the following code i need to get s1 = s2. I believe s1 is correct but not s2. Can someone tell me what am I doing wrong to compute the summation s2


s1=0; l=0.0127; h=6; P = 170; Po = 177; t = 3*3600; phi = 0.025; uc = 1.62e-11;
beta = [127.391000000000 372.323000000000 619.187000000000 866.339000000000 1113.58700000000 1360.87900000000 1608.19600000000 1855.52600000000 2102.86500000000 2350.21100000000 2597.56200000000 2844.91500000000]

for n = 1:length(beta)
    s1 = s1 + (exp(-1e-25*beta(n)^2*t/(phi*uc))/(l*(beta(n)^2 + h^2)+h))
end
s2 = sum(exp((-1e-25*beta.^2*t)/(phi*uc))/(l*(beta.^2 + h^2)+h))

Result:
s1 =

   0.005790696529312


s2 =

    1.474478992007853e-005

Subject: can you help me find the mistake here

From: Roger Stafford

Date: 14 Oct, 2010 19:36:04

Message: 2 of 4

"salamay " <coldfusion99@gmail.com> wrote in message <i97ktj$295$1@fred.mathworks.com>...
> In the following code i need to get s1 = s2. I believe s1 is correct but not s2. Can someone tell me what am I doing wrong to compute the summation s2
>
>
> s1=0; l=0.0127; h=6; P = 170; Po = 177; t = 3*3600; phi = 0.025; uc = 1.62e-11;
> beta = [127.391000000000 372.323000000000 619.187000000000 866.339000000000 1113.58700000000 1360.87900000000 1608.19600000000 1855.52600000000 2102.86500000000 2350.21100000000 2597.56200000000 2844.91500000000]
>
> for n = 1:length(beta)
> s1 = s1 + (exp(-1e-25*beta(n)^2*t/(phi*uc))/(l*(beta(n)^2 + h^2)+h))
> end
> s2 = sum(exp((-1e-25*beta.^2*t)/(phi*uc))/(l*(beta.^2 + h^2)+h))
>
> Result:
> s1 =
>
> 0.005790696529312
>
>
> s2 =
>
> 1.474478992007853e-005
- - - - - - - - - - -
   In s2 you are lacking the dot in the division operation. It should read

s2 = sum(exp((-1e-25*beta.^2*t)./(phi*uc))/(l*(beta.^2 + h^2)+h))

This is necessary to obtain element-by-element divsions rather than matrix division which is a different operation.

Roger Stafford

Subject: can you help me find the mistake here

From: salamay

Date: 14 Oct, 2010 20:15:10

Message: 3 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i97m34$ikt$1@fred.mathworks.com>...
> "salamay " <coldfusion99@gmail.com> wrote in message <i97ktj$295$1@fred.mathworks.com>...
> > In the following code i need to get s1 = s2. I believe s1 is correct but not s2. Can someone tell me what am I doing wrong to compute the summation s2
> >
> >
> > s1=0; l=0.0127; h=6; P = 170; Po = 177; t = 3*3600; phi = 0.025; uc = 1.62e-11;
> > beta = [127.391000000000 372.323000000000 619.187000000000 866.339000000000 1113.58700000000 1360.87900000000 1608.19600000000 1855.52600000000 2102.86500000000 2350.21100000000 2597.56200000000 2844.91500000000]
> >
> > for n = 1:length(beta)
> > s1 = s1 + (exp(-1e-25*beta(n)^2*t/(phi*uc))/(l*(beta(n)^2 + h^2)+h))
> > end
> > s2 = sum(exp((-1e-25*beta.^2*t)/(phi*uc))/(l*(beta.^2 + h^2)+h))
> >
> > Result:
> > s1 =
> >
> > 0.005790696529312
> >
> >
> > s2 =
> >
> > 1.474478992007853e-005
> - - - - - - - - - - -
> In s2 you are lacking the dot in the division operation. It should read
>
> s2 = sum(exp((-1e-25*beta.^2*t)./(phi*uc))/(l*(beta.^2 + h^2)+h))
>
> This is necessary to obtain element-by-element divsions rather than matrix division which is a different operation.
>
> Roger Stafford

Oh you are a life saver.

It drove me nuts and i didn't realize

Thanks Roger

Subject: can you help me find the mistake here

From: salamay

Date: 14 Oct, 2010 20:15:10

Message: 4 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i97m34$ikt$1@fred.mathworks.com>...
> "salamay " <coldfusion99@gmail.com> wrote in message <i97ktj$295$1@fred.mathworks.com>...
> > In the following code i need to get s1 = s2. I believe s1 is correct but not s2. Can someone tell me what am I doing wrong to compute the summation s2
> >
> >
> > s1=0; l=0.0127; h=6; P = 170; Po = 177; t = 3*3600; phi = 0.025; uc = 1.62e-11;
> > beta = [127.391000000000 372.323000000000 619.187000000000 866.339000000000 1113.58700000000 1360.87900000000 1608.19600000000 1855.52600000000 2102.86500000000 2350.21100000000 2597.56200000000 2844.91500000000]
> >
> > for n = 1:length(beta)
> > s1 = s1 + (exp(-1e-25*beta(n)^2*t/(phi*uc))/(l*(beta(n)^2 + h^2)+h))
> > end
> > s2 = sum(exp((-1e-25*beta.^2*t)/(phi*uc))/(l*(beta.^2 + h^2)+h))
> >
> > Result:
> > s1 =
> >
> > 0.005790696529312
> >
> >
> > s2 =
> >
> > 1.474478992007853e-005
> - - - - - - - - - - -
> In s2 you are lacking the dot in the division operation. It should read
>
> s2 = sum(exp((-1e-25*beta.^2*t)./(phi*uc))/(l*(beta.^2 + h^2)+h))
>
> This is necessary to obtain element-by-element divsions rather than matrix division which is a different operation.
>
> Roger Stafford

Oh you are a life saver.

It drove me nuts and i didn't realize

Thanks Roger

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us