-
Sep 18th, 2011, 12:02 PM
#1
Thread Starter
New Member
Add Until [Function]
Hey guys!
I was just bored and had nothing to do so I made this super duper easy function. Let me tell you what it does.
Let us say, that we have a math thing to do
? + 321 = 485
And we are really stupid so we dont know how to solve it. We do like this.
We use my function!
Code:
Public Function Add(byval intyouknow as integer, byval intresult as integer)
Dim i as integer = 0
Do until i + intyouknow = intresult
i = i + 1
Loop
Return i
End Function
This is pretty obvious what it does so here's how we are going to solve our "tricky situation"
Code:
Messagebox.Show(add(321,485))
And that will return 164, since 164 + 321 = 485 (DERP)
Hope you liked it!
-
Sep 18th, 2011, 12:50 PM
#2
Re: Add Until [Function]
You want to make that a bit faster?:
Code:
Public Function Add(ByVal intyouknow As Integer, ByVal intresult As Integer) As Integer
Return intresult - intyouknow
End Function
That will do the exact same thing without the For loop; which if you have really big numbers, will slow it down.
-
Sep 18th, 2011, 01:01 PM
#3
Thread Starter
New Member
Re: Add Until [Function]
Originally Posted by formlesstree4
You want to make that a bit faster?:
Code:
Public Function Add(ByVal intyouknow As Integer, ByVal intresult As Integer) As Integer
Return intresult - intyouknow
End Function
That will do the exact same thing without the For loop; which if you have really big numbers, will slow it down.
Ah that's awesome dude
Didn't know that!
-
Sep 20th, 2011, 09:09 AM
#4
Re: Add Until [Function]
You are aware that you just called yourself really stupid?
-
Sep 21st, 2011, 08:13 PM
#5
Re: Add Until [Function]
I'd rather one for this: X^Y=Z where X is the unknown. It's a logarithm, but I don't know how to calculate it. Let's make this thread useful!
-
Sep 22nd, 2011, 09:07 AM
#6
Re: Add Until [Function]
I was looking on the internet for some examples on what minitech said and I couldn't figure out how to use logs for his problem, but then I realized that it was not needed.
Code:
X^7=16384
16384^(1/7)=4
4^7=16384
-
Sep 22nd, 2011, 08:18 PM
#7
Re: Add Until [Function]
Can you verify that with logarithms by hand?
-
Sep 23rd, 2011, 12:08 AM
#8
Re: Add Until [Function]
Why ? Isn't this simpler than log's ? In any case I haven't done logs at school yet so I don't really know how.
-
Sep 23rd, 2011, 10:32 AM
#9
Re: Add Until [Function]
@formlesstree4: It would be more complicated, but sure; log(4, 16384) = 7. And now, from W|A I know that log(1/y, z) = ln(z) / ln(y). Thanks!
-
Sep 23rd, 2011, 11:43 AM
#10
Re: Add Until [Function]
You don't need to use logs, that's just silly. It boils down to the same thing in the end anyway (of course), you just use the root...
Suppose a and b are given and you need to solve for x:
x^a = b
Then x = b^(1/a).
In case a = 2, everyone knows this. If x^2 = b, then x = sqrt(b) = b^(1/2). Give or take a minus sign.
It's the same when a is not 2, you just take the 'a'th root instead of the square root.
Now logs...
You correctly state that
log(b) / log(x) = a.
But how does that help? Let's calculate...
And we get exactly the same result... So, useless, don't use logs
As for x^7 = 16384, the answer x = 4 is not the only answer, there are 6 more answers, but they are all complex:
Last edited by NickThissen; Sep 23rd, 2011 at 11:46 AM.
-
Sep 23rd, 2011, 11:49 AM
#11
Re: Add Until [Function]
Originally Posted by NickThissen
You don't need to use logs, that's just silly. It boils down to the same thing in the end anyway (of course), you just use the root...
Suppose a and b are given and you need to solve for x:
x^a = b
Then x = b^(1/a).
In case a = 2, everyone knows this. If x^2 = b, then x = sqrt(b) = b^(1/2). Give or take a minus sign.
It's the same when a is not 2, you just take the 'a'th root instead of the square root.
Now logs...
You correctly state that
log(b) / log(x) = a.
But how does that help? Let's calculate...
And we get exactly the same result... So, useless, don't use logs
As for x^7 = 16384, the answer x = 4 is not the only answer, there are 6 more answers, but they are all complex:
WELL LOOK AT YOU MR. MATHEMATICS PERSON! Nice proof though. I guess you had some free time eh?
EDIT: I asked for a logarithmic proof because minitech's question involved logarithms. 'tis all.
-
Sep 23rd, 2011, 11:50 AM
#12
Re: Add Until [Function]
Nick you probably didn't just find that last image on the net. Where did you get it, it looks like a cool program ?
-
Sep 23rd, 2011, 11:54 AM
#13
Re: Add Until [Function]
Originally Posted by formlesstree4
WELL LOOK AT YOU MR. MATHEMATICS PERSON! Nice proof though. I guess you had some free time eh?
EDIT: I asked for a logarithmic proof because minitech's question involved logarithms. 'tis all.
10 seconds is all I needed. Come on, this is basic math isn't it?
Originally Posted by BlindSniper
Nick you probably didn't just find that last image on the net. Where did you get it, it looks like a cool program ?
Maple. I was too lazy to type it out so I had Maple calculate it for me
WolframAlpha can give you pretty much the same answer though:
http://www.wolframalpha.com/input/?i...7+%3D+16384%29
-
Sep 23rd, 2011, 12:00 PM
#14
Re: Add Until [Function]
Should we start a codebank entry for math functions instead of hijacking a thread ?
-
Sep 23rd, 2011, 12:17 PM
#15
Hyperactive Member
Re: Add Until [Function]
Originally Posted by BlindSniper
Should we start a codebank entry for math functions instead of hijacking a thread ?
Wait, am i late for the math class????
-
Sep 23rd, 2011, 12:38 PM
#16
Re: Add Until [Function]
Originally Posted by NickThissen
It is basic math, I'm just messing with you
-
Sep 23rd, 2011, 01:33 PM
#17
Re: Add Until [Function]
@NickThissen: I know logs weren't the answer to the problem, I was asking how to calculate them. I always see constants like: LOG_2_E so I assumed there wasn't a better way to calculate them than log(x, y) = log(x, e) * ln(y).
-
Sep 23rd, 2011, 02:32 PM
#18
Re: Add Until [Function]
There's infinitely many logarithms, each with their own 'base' as you probably know. The function 'log' usually corresponds to the logarithm with base 10, often written log10(x). Sometimes it also refers to the natural logarithm or ln(x) = loge(x).
To switch from one base to another you just divide by the log of that base:
log3(x) = logy(x) / logy(3)
In this case y is irrelevant, as long as you use the same in numerator and denominator.
Judging from your formula, with log(x, y) you mean logy(x) = loge(x) / ln(y) = loge(x) / loge(y) = ln(x) / ln(y).
Since the natural logarithm (ln, base e) is often considered 'more fundamental', logs in a different base are sometimes 'defined' as a ratio of natural logarithms as above -- logy(x) = ln(x) / ln(y).
-
Sep 23rd, 2011, 04:33 PM
#19
Re: Add Until [Function]
Originally Posted by NickThissen
There's infinitely many logarithms, each with their own 'base' as you probably know. The function 'log' usually corresponds to the logarithm with base 10, often written log10(x). Sometimes it also refers to the natural logarithm or ln(x) = loge(x).
To switch from one base to another you just divide by the log of that base:
log3(x) = logy(x) / logy(3)
In this case y is irrelevant, as long as you use the same in numerator and denominator.
Judging from your formula, with log(x, y) you mean logy(x) = loge(x) / ln(y) = loge(x) / loge(y) = ln(x) / ln(y).
Since the natural logarithm (ln, base e) is often considered 'more fundamental', logs in a different base are sometimes 'defined' as a ratio of natural logarithms as above -- logy(x) = ln(x) / ln(y).
I wish my PreCalc teacher explained it the same way you did. It's a really good and simple explanation of converting log bases, which can be very fun.
-
Sep 23rd, 2011, 06:24 PM
#20
Re: Add Until [Function]
How are you doing subscripts??! sub? Oops, I guess I just got it there. Nevermind.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|