# How fast would a computer do this?

1. Feb 10, 2008

### disregardthat

Hi, I have little experience with computer and programming (just a little on my calc) and I wonder how fast a computer really is. Would it be a problem for a computer to "graph", that will say calculate several expression frequently for different inputs at once?

I have about 40 expressions kind of like this:

$$f(x)=([A_1x+B_1+C_1sin(D_1(x-E_1)]^2+[A_2x+B_2+C_2sin(D_2(x-E_2)]^2)^{\frac{1}{2}}$$

$$A_k,B_k,C_k$$ and $$D_k$$ are constants.

And if a computer were to graph these at all times, how well would it handle it?

I know of course that the speed depends on the frequency of the calculations, but I want it fairly high, much higher than the calculator graph the curves.

2. Feb 10, 2008

Depends on the optimization of the program, processor speed, background processes, amount of RAM..........

3. Feb 10, 2008

### CompuChip

Probably the speed of a well written computer program will make your calculator look like a snail compared to it To get more specific information, you should be more clear about where the data come from, how you want to plot it, which program you have in mind, etc.

PS I just did a little test: in a very ugly hack-like first approximation, it takes me about 5 seconds to plot 40 of them with random $A_k, B_k, C_k, D_k$ simultaneously (and plotting consecutively makes it about 5x faster).

4. Feb 10, 2008

### disregardthat

Thanks for the replies.

I have as previously said very little experience with programming.

But I am trying to make this:

We specify coordinates to two rectangles, and the speed of rotation and the speed and direction of the centre.

Now, I have made out purely by vectors and their properties an algorithm of knowing when the rectangels hit eachother, and how they shall bounce off eachother.

I have:

Four vectorfunctions which describe the positions for each corner in each rectangle which is in this form:

$$\vec{r}(x)=[A_1x+B_1+C_1sin(D_1(x-E_1)),A_2x+B_2+C_2sin(D_2(x-E_2))]$$

That makes eight functions to graph at all times.

Now I have defined the radius of the rotation circle of each rectangle to be R and R'. Now I have also made a similar vectorfunction for the positions of the centres S and S' in each rectangle, and when |\vec{SS'}| <= R+R', (the distance between the centers is less than the radius of each rotation circle) then I want several calculations to be made:

I want to calculate several distance formulas from each corner in one rectangle to every other point in the other rectangle. I use a method by using vector dot-product to see when a corner of one rectangle is on the edge of the other rectangle, basically when they touch eachother. But this requires many functions to calculate at all times, e.g. the distance functions from the points. When I sum they up, there are about 40-80 of these functions that I want to be calculated at all times, and when a specific value appears, I want the "collision" stage start. Which will make several differences in the path and rotation speed of the rectangles.

Perhaps a bit babbly, but I hope you see what I mean. As you obviously can see, this wont work on a calculator, I need a computer, but first I want to know if this is possible.

Thanks

Last edited: Feb 10, 2008
5. Feb 10, 2008

### mgb_phys

Remember computers are fast. If it takes a couple of 1000 calculations to find a hit then you can still do 1million/sec! Especially since the amount of memory used if very small and so will fit in cache.
There are a lot of tricks to speed-up collision algorithms - they are very heavily used in games. For more complicated shapes your graphics card probably has hardware to do it for you.

6. Feb 10, 2008

### CaptainQuasar

Just eyeballing it it doesn't look too bad at all. You would want to use something like Mathematica or Matlab or Maple for this.

If there's a university or college with a Mathematics or Physics department near you they may have computer labs with one of these programs available that you can just walk in and use.

7. Feb 10, 2008

### disregardthat

CaptainQuasar: Can you use Matlab to create such a program? I have heard good things about it.

mgb_phys: I am interested in these methods to speed up collision algorithms, do you have a source of information?

8. Feb 10, 2008

### mgb_phys

Last edited: Feb 10, 2008
9. Feb 10, 2008

### disregardthat

Hey, thanks for the links. I wonder though, could you take a look at the ideas I have if I wrote them down in lucid form and tell me if theres something worth trying? You seem to know this stuff. I have never done anything like this, or read anything about it. It will only be a few pages.

Last edited: Feb 10, 2008
10. Feb 10, 2008

### CaptainQuasar

Matlab etc. wouldn't create a program. Those programs are themselves like graphing and symbolic calculators.

11. Feb 11, 2008

### disregardthat

Do you know of a program which is much like the calculator Texas's way of programming? It's the only programming language I know of. I have made a sketch on how the program should be now, so I really just need something to program it into.

12. Feb 11, 2008

### CaptainQuasar

No, you would probably have to learn to program / write commands for whatever software you're using. But if you're going to continue with math in school it's well worth it to spend the time learning, these programs can do amazing things. My favorite is Mathematica. When I was in school I always dreamed about buying a palmtop computer like the Oqo and running Mathematica on it, rather than using a graphing calculator.

Here's an open source one called Gnuplot. It's probably more difficult to use and less versatile than the commercial ones I mention above but it's free so you can download it and try it out right now. But also, if you're willing to spend some money and you're a student you probably can qualify for a student discount of one of the commercial ones, which would probably put it between US$100-US$200.

13. Feb 12, 2008

### CompuChip

If you're a student, first check with your local computing department if they don't have it available for you. At my university, we can just go and get a Mathematica installation CD and we are allowed to you the program for free (of course, the license is only valid while you are actually registered as a student).

14. Feb 12, 2008

### CRGreathouse

Each evaluation requires getting 4 constants from memory and doing maybe 10 bit operations (6 additions, 2 subtractions, 2 for some kind of shuffling around with registers), 8 multiplications, a square root, and two sines. If the sines and roots take 60 cycles and the multiplications take 10, and the floating point ops can run side-by-side with the integer ops, then you're talking at least 180 cycles, and possibly as many as 300 if everything is blocking and there's a lot of shuffling needed.

If you're varying the x coordinates and keeping the constants, um, constant, then each graph takes 8 * (180 to 300) * number of x points total cycles. For a thousand points that would be 1.4 to 2.4 million cycles; for ten thousand that would be 14 to 24 million. If you do nothing else, a 1 GHz processor core could do 416 to 714 (thousand) or 41 to 72 (ten thousand) refreshes per second. With a fast lookup table for sines and such this could be lower.

If you use the packed SSE instructions you could probably get a factor of 2 speedup as well.

15. Feb 13, 2008

### disregardthat

Hey, thanks for the information. Now I think I can lower the equations to about 16 of these:

f(x)=Asin[B(x-D)]+E+Fx

I found a much better idea to find when each collision occur. Instead of calculating each step to see if a point is touching a side, I can rather calculate WHEN it will occur, and at that t, the collision stage begin. So it's basically just those mentioned above, plus 32 equations which will only be calculated once. I think I could do it on my graphics calculator too (kind of slow though), if I only had two more spots for parameterised curves :\ I only have 6 spots, and I need 8.

I wonder, is there any way to get more variables than A to Z and theta? And I'd appriciate if someone told me how to get more spots on parameterised curves. I have a TI-84 Texas.

Last edited: Feb 13, 2008