## Prog Help plz

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Disk1of64
Newbie
Posts: 5
Joined: Fri Jul 27, 2007 3:59 pm

### Prog Help plz

Hello again peoples!

Its been a long while since I have had a chance to sit down with tutorials and such. Starting a new jobm studying, and moving at the same time sucks. I wanted to throw up a quick post to see if you can help an extremely outta practice nooB. I finally got an idea for a program, something I can use for a game. I need some code help in which way to get started and such. The premise is this:

I need a program that will "predict" a set of numbers that are part of a chart....if thats possible. The program will get fed numbers for the rows across, ranging from 24-30. The collum going down will just be a generic number (i.e. 1-14). The second chart will work the same way only be smaller. Any of this making sense? See Below:

1)24,24,26,28,27,(predict the next number)
2)27,30,30,29,24,(predict the next number)
3)29,29,29,29,25,(predict the next number)
4)30,24,25,26,27,(predict the next number)
5)27,28,28,24,26,(predict the next number)

Thnx again for all suggestions and help!

Raspberrypicker
Veteran
Posts: 55
Joined: Thu Aug 02, 2007 4:54 pm
Location: Florida
Hi disk.

I think I got what you need...but I'm not sure. But this is a little sample program I made. You can run it on qb, i checked it to make sure it works.

Code: Select all

``````CLS                                 'clears screen

DIM chart(5)                    'alerts qbasic that you have an array in your program

chart(2)=(n+3)
chart(3)=(n-3)
chart(4)=(2*n)
chart(5)=(n^2)

FOR count = 1 TO 5           'loop to print your array
PRINT chart(count)
NEXT
``````
In this program, it sets up an array, so you can fill in values for your chart.

I'm not sure about the algorithms you set up, and I don't know the pattern...but if you know the pattern, just substitute the equations in place of my equations. (it helps to know a bit about algebra, it can greatly help you set up algorithms.)
Fruit Pickin'

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
Oh!
Those are polynomial vertieces.

Let's see:

f(x)=ax?+bx+c

Use the power rule and you get:
where the highest number = -b/(2a), if it's just a parabola.

So, if f(x)=A*X^N +B*X^(N-1) +...+Y*X^2+Z*X+C
then all of the high/low points are:
A*N*X^(N-1)+B*(N-1)*X^(N-2)+...+2*Y*X+Z=0
In theory, the computer could solve it, but it would be a monster. Not to mention debugging.

It's soemthing along the lines of f(x+1)-f(x)=f'(x), but with rounding (I think, but it might be some higher order polynomial, in which case it's
just plug and chug)

So ax?+bx+c=f(x+1)-f(x)
...
Now I'm stuck .

You need to find f(x), and then find the data after the last.

I saw a way to do it with matricies. Graphing calculators can also do it in a cinch.

ThemePark
Coder
Posts: 17
Joined: Wed Aug 22, 2007 6:37 pm
Disk1of64, I'm not quite sure what it is that you want to do. Do you have some mathematical formulas at hand that you want to use with a row of numbers and then predict the forthcoming numbers, or do you somehow want the program to calculate a formula from the numbers you're given?

Also, I must admit I'm not quite sure how Mentat realized that those are polynomial.

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
Also, I must admit I'm not quite sure how Mentat realized that those are polynomial.

Do the wave.

Here's are rough sketch of a graph:
1) _/\
2) /^\
3) ---\
4) \_/
5) /^\_/
My text art is horrible but the data basicaly goes up and down.
For any grievances posted above, I blame whoever is in charge . . .

Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

### Re: Prog Help plz

Disk1of64 wrote: 1)24,24,26,28,27,(predict the next number)
2)27,30,30,29,24,(predict the next number)
3)29,29,29,29,25,(predict the next number)
4)30,24,25,26,27,(predict the next number)
5)27,28,28,24,26,(predict the next number)
Well, you say you are out of practice programming. Maybe so, but this is not a programming problem. It is a mathematics/statistics problem. And my guess is that it has no solution.

You must know the formula that produced those numbers. As a human staring at those sequences, I have no clue. They could well be random numbers.

Take 4) for instance
30, 24,25,26,27

If I HAD to guess, I would say 28. But the series might be
30, 24,25,26,27,31,25,26,27,28,32,26,....
or
30, 24,25,26,27,26,25,24,30,24,25......

So before anyone can write a program, one has to know how to solve the problem without a computer.

Writing programs is easy. Solving problems is tough. Write a program to predict the stock market tomorrow. Easy if you first tell me how to predict the stock market tomorrow.

Mac

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
Any finite set of data can be modeled by an infinite set of functions.

Humans pick the functions by what we know and what seems more efficient. Computers don't have base 'intuition' and so try to do it the way humans do it: picking what's been programmed.

For example:
1,2,3,4,5,_
You'd say six. But there are an infinite amount of answers. But six is a good number.

Think of it this way: using the simplest polynomial, you could have numbers going through all points certain angles. Add more terms, change the cofficients, and lines go through same points, but at different angles. Since there are an infinite amount of slopes/angles, there are an infinite amount of possibilities.

But it isn't impossible.
For any grievances posted above, I blame whoever is in charge . . .

nyfiken
Newbie
Posts: 7
Joined: Sun Aug 26, 2007 11:57 pm
Couldn?t one use some form of neural network to make predictions? Are there any written for Qb?
________
Hysterectomy forums
Last edited by nyfiken on Tue Feb 15, 2011 10:32 pm, edited 1 time in total.

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
There's a better way to find some answers. Just use matricies and the inverse property. I forgot how, and it takes more work as the terms increase.
For any grievances posted above, I blame whoever is in charge . . .

Raspberrypicker
Veteran
Posts: 55
Joined: Thu Aug 02, 2007 4:54 pm
Location: Florida
If you're solving a system of linear equations, the substitution or elimination method is the way to go. Matrices are just more work, unless you have a graphing calculator...or even better...you make a program that works like a TI-83
Fruit Pickin'

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
TI-83's use matricies and some weird statistic thing to solve. Or limits, they work too.

That's the advantage of TI-BASIC: it can do all of that fancy math, albeit slowly.
For any grievances posted above, I blame whoever is in charge . . .