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:
Finding the sum of 1/matrix

Subject: Finding the sum of 1/matrix

From: Diego Zegarra

Date: 18 Feb, 2009 16:45:04

Message: 1 of 3

Lets say we have a vector,

S = [12;13;15;11;16]

and I am trying to find the sum of 1 over each number, so:

1/12+1/13+1/15+1/11+1/16

I know it can be done with a simple loop, just wondering if there is a function or faster way for that.

for s=1:5
       SI(s)=1/S(s);
end
S_Sum = sum(SI)

Thanks!

Subject: Finding the sum of 1/matrix

From: Sven

Date: 18 Feb, 2009 17:08:02

Message: 2 of 3

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gnhdug$40m$1@fred.mathworks.com>...
> Lets say we have a vector,
>
> S = [12;13;15;11;16]
>
> and I am trying to find the sum of 1 over each number, so:
>
> 1/12+1/13+1/15+1/11+1/16
>
> I know it can be done with a simple loop, just wondering if there is a function or faster way for that.
>
> for s=1:5
> SI(s)=1/S(s);
> end
> S_Sum = sum(SI)
>
> Thanks!

Try the ./ operator

tmp = [5 8; 2 1]
1 ./ tmp

Cheers,
Sven.

Subject: Finding the sum of 1/matrix

From: dpb

Date: 18 Feb, 2009 17:33:34

Message: 3 of 3

Diego Zegarra wrote:
> Lets say we have a vector,
>
> S = [12;13;15;11;16]
>
> and I am trying to find the sum of 1 over each number, so:
>
> 1/12+1/13+1/15+1/11+1/16
...
s=sum(1./S)

--

Tags for this Thread

No tags are associated with 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