[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 548 KB, 1024x768, Lighthouse.jpg [View same] [iqdb] [saucenao] [google]
5740157 No.5740157 [Reply] [Original]

(n+2)/(n+1), sum of all terms from n=1 to n=49?

>> No.5740161

is there a smart way to compute this?

>> No.5740163

>>5740161

Yes, it's called a computer program.

>> No.5740166

>>5740163
This. I'll write one for you OP since I'm bored.

>> No.5740167

>>5740163
i have to write a c++ to compute this.
was thinking of some kind of riemman sum

>> No.5740169

http://www.wolframalpha.com/input/?i=sum+%28n%2B2%29%2F%28n%2B1%29+from+n%3D1+to+49

>> No.5740175

>>5740167
Here it is in python. The results are 1 for all values of n. Adding them all up gives 49.


# The function you want to call for different values of n
def func(n):
return (n+2)/(n+1)
n = 1
results = [] #an empty list

# call the function for all values of n and store each result in the results list.
while n < 50:
result = func(n)
results.append(result)
n += 1
print results
print sum(results) # built in function for summing a list of numbers.

>> No.5740178

>>5740175
damn. python code is impossible to read without indents isn't it? sorry about that.


---------------------------
# The function you want to call for different values of n
def func(n):
return (n+2)/(n+1)
---------------------------

n = 1
results = [] #an empty list

---------------------------
# call the function for all values of n and store each result in the results list.
while n < 50:
result = func(n)
results.append(result)
n += 1
---------------------------

print results
print sum(results) # built in function for summing a list of numbers.

>> No.5740180

>>5740169
>http://www.wolframalpha.com/input/?i=sum+%28n%2B2%29%2F%28n%2B1%29+from+n%3D1+to+49


got an 1% error by integration "on top" and "under".

>>5740175
thanks, but i don~t understand lol.

52.24 < 52.49.... < 52.91

>> No.5740189

>>5740175
>>5740178
You really suck at this. Doesn't Python have something like map and ranges? Or did Guido von Cocksucker got rid of lambdas for good? For example, in matlab/octave, sum(map(@(n) (n+2)/(n+1), 1:49)). And since we are on the subject of languages, people should start to use Julia. It's perfect. http://julialang.org/

>>5740180
Why do you want do it by integration? It's a sum, not an integral, then sum it goddamit.

>> No.5740190

>>5740180
>>5740189
Sorry about that. My code also rounds by mistake since it's using int's instead of floats, and the function always returns "1". Forcing it to use floats the final number returns 52.4992053383

>> No.5740196
File: 215 KB, 816x435, how js.png [View same] [iqdb] [saucenao] [google]
5740196

>>5740157
just write the programs in the address field

javascript:var sum=0;for(var i=1;i<=49;i++)sum+=+((i+2)/(i+1));alert(sum);

>> No.5740198

>>5740196
>write the programs in the address field
"So what do you normally program in?"
"The address bar of my browser."

>> No.5740202

>>5740190
Python isn't good for numerical computations, even on a toy level. And NumPy/SciPy is just... weird. The general purpose-ness of the language still gets in the way, judging from some of the snippets I've seen around the internet. I don't want to use any "array" function or whatever shite when I want to define a matrix. That's silly.

>> No.5740204

>>5740198
well, with addressbarscript you won't need an external interpreter or compiler and the programs are pretty short
just compare my line with that python abomination up there which won't even run because the indentation is missing and OP probably doesn't have a compiler for it, now he can just copy, paste in address bar and get results in a popup

everybody should know addressbarscript

>> No.5740206

>>5740189
want to do it by integrations cause i don't want to spend all day summing fractions :(

>> No.5740210

>>5740204
It doesn't work for me. Chromium version 25.0.1364.160 Ubuntu 13.04. So it's not as ubiquitous as you'd think. And it's probably a good thing, since I'd rather not some weird links executing arbitrary javascript on my computer.

>>5740206
So you want to do it analytically? With pencil and paper?

>> No.5740211

>>5740204
Didn't work for me.

>> No.5740216

>>5740210
>>5740211
In most browsers, executing javascript in the address bar is disabled for security reasons. You have to change your settings.

>>5740202
I know I really only use it for small programs.

>> No.5740217

>>5740216
Well there's a rather good reason for those security settings, I'd say. Anyway, in Chrom(e/ium), menu->tools->Javascript console. You can run it there.

>> No.5740231

>>5740216
>In most browsers, executing javascript in the address bar is disabled for security reasons. You have to change your settings.
It's really not.
you might have disabled it manually but it's not disabled by default in any browser i know of and it should work even for the very early versions of IE

>>5740217
>Well there's a rather good reason for those security settings, I'd say.
yeah, nah, you just went with your feels on that.
you do know pretty much all sites are executing js on your computer without your explicit confirmation? most even use the exact type of link that i just posted, they're a crucial part of webdev.
and if you're using chrome/ium it automatically runs tracking scripts on every site you visit.
unless you disabled js manually, in which case it's not my fault that the script won't run.

make sure you actually copied the "javascript:" part too.

>> No.5740236

>>5740210
Yeah, thats how i roll.

>> No.5740237

>>5740231
>https://support.mozilla.org/en-US/questions/885558
>Starting in Firefox 6 javascript in the url-bar runs with a null security principal for security reasons. This means it's almost disabled. You need a bookmarklet or an add-on for a workaround.

>> No.5740270

#include <iostream>

using namespace std;

double sumOfTerms(int n)
{
return (double)(n+2)/(n+1);
}

int main( int argc, char* argv[] )
{
double totalSum;
for(int i = 0; i < 50; i++)
totalSum += sumOfTerms(i);

cout << totalSum;

}

hurdur?

>> No.5740275

>>5740236
Well, if you want to do it by integration, you could do
<span class="math">\sum_{k=1}^{49} \frac{n+2}{n+1} = \sum 1 + \frac{1}{n+1} = 49 + \int_0^1\sum_{k=1}^{49}x^k dx= 49 + \int_0^1 \frac{x-x^{50}}{1-x}dx[/spoiler].

I have no idea how to solve that integral withour reversing back to sums. It doesn't have a pole at 1, which sucks. Otherwise it could be doable by some contour integration. You wanted an integral, there you have it.

>> No.5740278

>>5740237
I didn't know they caved in to the facebook account hackers tricking 13 year olds and disabled everything, that's sad it was very useful.

I was wrong, sorry about that.

>> No.5740294

is there a closed form solution?

>> No.5740318

>>5740294
I doubt it. WolframAlpha doesn't know it either.

>> No.5740338 [DELETED] 

(n+2)/(n+1) = 1 + 1/(n+1) = 1 - n/(n+1) + (n+1)/(n+2)

summing to 49 then gives 49 - 1/2 + 50/51

>>5740163
>>5740166
>>5740167
>>5740175
>>5740178
>>5740180
>>5740189
>>5740190
>>5740196
>>5740198
>>5740202
>>5740204
>>5740206
>>5740210
>>5740211
>>5740216
>>5740217
>>5740231
>>5740236
>>5740237
>>5740270
>>5740275
>>5740278
retards

>> No.5740353

>>5740338
Except that's wrong, retard. Maybe try checking at least the fucking wolfram alpha before you start embarrassing yourself

49 - 1/2 + 50/51 - sum(n->(n+2)/(n+1), [1:49])
> -3.0188131814666974

People who suck at manipulating fractions shouldn't be allowed to post on /sci/.

>> No.5740356

You can put it to 48+H_50 where H is harmonic number

>> No.5742041

You might want to consider that (n+2)/(n+1)=1+[1/(n+1)]
The second term give 1/2+1/3+1/4 etc.
The first term gives 49.

>> No.5742053

>>> from fractions import Fraction
>>> sum(Fraction(n+2,n+1) for n in range(1,50))

>> No.5742209
File: 106 KB, 1280x768, untitled.png [View same] [iqdb] [saucenao] [google]
5742209

everyone who didn't do this is a pussy

>> No.5742232

if you do it in python this way, you clearly do not understand how to write pythonic code
print(sum([float(x+2)/(x+1) for x in range(1,50)]))

>> No.5742239

If you needed a computer to calculate this, you are terrible at mathematics.

>> No.5742356

What >>5742239 said.

>> No.5742385

>>5742239
>If you needed a computer to calculate this, you are terrible at mathematics and/or lazy.
Fixed.