Naked Science Forum

Non Life Sciences => Geek Speak => Topic started by: Dege on 12/01/2009 03:55:34

Title: how to write a algorithm
Post by: Dege on 12/01/2009 03:55:34
I have been haveing some trouble learning how to write algorithms. can anyone help me?
Title: how to write a algorithm
Post by: Chemistry4me on 12/01/2009 03:57:21
Are you talking maths or computers?
Title: how to write a algorithm
Post by: Dege on 12/01/2009 23:24:54
computers
Title: how to write a algorithm
Post by: DoctorBeaver on 12/01/2009 23:37:40
You have to break it down to single, linear steps. What do you want your algorithm to do?
Title: how to write a algorithm
Post by: Dege on 14/01/2009 01:31:46
just to predict the next outcome of a numer sequence just somethiing simple like that can you tell me how to do that
Title: how to write a algorithm
Post by: DoctorBeaver on 14/01/2009 02:12:04
You have got to be joking! Do you realise how complicated that is? In order to predict the next number you first have to work out what the connection is between the numbers you have to start with.

Can't you start with something simple like an atmospheric model!?  [:P]
Title: how to write a algorithm
Post by: RD on 14/01/2009 12:18:34
just to predict the next outcome of a number sequence just something simple like that can you tell me how to do that

If the numbers are points on a smooth line it should be possible to extrapolate (http://en.wikipedia.org/wiki/Extrapolation) to the next number.
Title: how to write a algorithm
Post by: dentstudent on 14/01/2009 12:30:37
just to predict the next outcome of a number sequence just something simple like that can you tell me how to do that

If the numbers are points on a smooth line it should be possible to extrapolate (http://en.wikipedia.org/wiki/Extrapolation) to the next number.


Certainly, if you are dealing with standard linear relationships. But that assumes that the number sequence consists of numbers that are "related" and dependent. If they are entirely independent, you have no chance. But let's assume that we're dealing with a dependent variable. Curve fitting is rather difficult unless, as Eth says, you already know what the relationship is.

It would be easier to comment if we knew what numbers we were dealing with, and what sort of prediction is required.
Title: how to write a algorithm
Post by: dentstudent on 14/01/2009 12:32:13
just to predict the next outcome of a numer sequence just somethiing simple like that can you tell me how to do that

I can however show you where the capital letters are, as well as commas, question marks and full-stops!
(FOG)
Title: how to write a algorithm
Post by: Dege on 14/01/2009 20:53:55
haha ok sorry guys can yall start me off with just the basics of algorithms and lets work from there
Title: how to write a algorithm
Post by: RD on 14/01/2009 23:54:13
Draw a flow diagram (http://en.wikipedia.org/wiki/Functional_flow_block_diagram).
 
If you told us the intended function we may be able to tell you if it is possible and how complex the programme would have to be,
 e.g. if you are looking to create a programme which can predict lottery numbers you're wasting your time.

http://en.wikipedia.org/wiki/Software_development_process
Title: how to write a algorithm
Post by: Dege on 15/01/2009 02:56:11
no its  not for anything like that ok just forget the predictions and just start me off with the simplest thing a algorithm can do, if you dont mind please.
Title: how to write a algorithm
Post by: RD on 15/01/2009 05:05:59
Here is a simple flow diagram ...

 [ Invalid Attachment ]
Title: how to write a algorithm
Post by: Chemistry4me on 15/01/2009 05:07:35
Haha, very good RD! Top notch!
Title: how to write a algorithm
Post by: DoctorBeaver on 15/01/2009 11:37:59
RD - don't start him on iterative loops!  [:D]
Title: how to write a algorithm
Post by: Dege on 15/01/2009 22:33:50
OK thanks allot that helps me out a great deal. OK now one last thing is there any article or download that you know of that can take me through the basics and help me out.thanks again
Title: how to write a algorithm
Post by: RD on 16/01/2009 04:04:00
Here is an article...

Quote
How to describe software design using diagrams and pseudo-code
http://www.scienceprog.com/how-to-describe-embedded-software-design-using-diagrams-and-pseudo-code/

Pseudo-code (http://en.wikipedia.org/wiki/Pseudocode) is a list of stepwise instructions in plain English, like DoctorBeaver mentioned above, it resembles computer code (a.k.a. computer programme).
Title: how to write a algorithm
Post by: Chemistry4me on 16/01/2009 05:14:42
Don't you ever go to sleep RD?
Title: how to write a algorithm
Post by: chrisn on 17/01/2009 09:08:45
Fibonacci numbers are generated by an algorithm which is easily converted into a computer program.

The first fibonacci numbers are:

0    1    1    2    3    5    8    13    21    34    55    

The ninth number is 21, which is the sum of the two previous numbers, 8 + 13.
Likewise, 55 = 34 + 21.
By definition, the first two are 0, 1.

If you want to generate the 100'th fibonacci number, it's easy to say that it is the sum of the 99'th and the 98'th number, but what their value is, being tedious fast.

If you want to generate these numbers in a programming language (there is example fibonacci code for basically every language), you define a function (my example is in python, a programming language):

def fibonacci(n): # Returns the n'th fibonacci number
   if n < 2:
     return n # The zero'th fibonacci number is 0, the first one is 1, by definition.
   else:
     return fibonacci(n - 1) + fibonacci(n - 2)

This is quite similar to the explanation in English. If you can describe an algorithm in English (or in math), converting it into a computer-language is quite simple, although you'll have to learn the language first. Describing in English (or in math), what the algorithm does, with all the corner-cases, that's the hard part.
Title: how to write a algorithm
Post by: Dege on 23/01/2009 00:40:10
OK i would like to thank you all. i am finally starting to get i [:)][img] t. thanks again and i am sorry for the wast of time>