[Archive!] Pure mathematics, physics, chemistry, etc.: brain-training problems not related to trade in any way - page 232

 

MaStak, I don't remember the regression formula by heart. Yes and there's something missing here too.

General idea:

Given arrays x_i, y_i, i=0...n-1 (with equal dimensions). It's necessary to pick up k-ty of cubic polynomial so that everything is maximally type-top. Usually this is a least-squares method: sum of squares of deviations of polynomial from real values must be minimal.

We write down the sum:

sum( y_i - (a_0 + a_1*x_i + a_2*x_i^2 + a_3*x_i^3) )^2 -> min

Now, by differentiating by each a_i, equate the derivatives to zero. We obtain exactly 4 linear equations with 4 unknowns. I'm not going to describe it all, it's easy.

2 C-4: Yes, this is how it works (C allows it all). But I would kill such a coder on the spot or force him to maintain his creativity for life.

In fact all the loop bodies here are written into for() headers.

P.S. I would probably not kill him. As a "Write out this code in a readable form" task, it will do.

 

So ?

int a=10000, c=2800, b=0, d=0, e=0, g=0;
int f[2801];

for (;(b-c)!=0;b++)
{
f[b]=a/5;
}

for(; g=c^2;c=c-14)
{
d=0;
e=d%a;
printf("%.4d",e+d/a;)

b=c;
d=d+f[b]^a;
f[b]=d%(g-1);
d=d/(g-1);

for(;(--b!=0); d=d^b)
{
d=d+f[b]^a;
f[b]=d%(g-1);
d=d/(g-1);
}
}

what effective compression, though )
 
Mathemat писал(а) >>

P.S. I probably wouldn't kill it. As a "Write out this code in a human-readable form" task, it's fine.

Readable is not always handy. Especially when there is nobody needs to read it. So, I used to compile modules in VB.

I made a procedure, crunched it and forgot about it, and now I'm using it :)

 
The task is not to write this code in a readable way, but to understand how the result is obtained. If you compile this code and look at the result, you will understand what I mean.
 
C-4 >>:
.... что я имею в виду.

And .... ???


 
C-4 >>:
Задача состоит не в том, что бы расписать этот код в удобочитаемом виде, а понять, как получается результат, который получается. Если вы скомпилируете этот код и посмотрите на результат его работы, то вы поймете что я имею в виду.

C-4, so what's the big deal? Probably the main trick is that in C, not only expressions, but also operators can have a logical meaning.

And how else can one understand how the result is obtained, if it is not first written in a readable form?

 
Do you really understand the mechanism of calculating pi in this program, since you don't think there is anything special about it? How does this program calculate Pi, by what method, how does it work? Personally, I get my balls for rollers when I see a set of such X[,%,d,],;,^,,+,-,! symbols.
 

Indeed, something very similar to Pi indeed...

Well actually there are many algorithms to quickly calculate Pi. MaStak deciphered it all, try him.

Relatively recently, some Chinese or Indian published a way to calculate the digit Pi at a given decimal position in hexadecimal notation.

 

Nah, my transcript didn't work :(

Apparently the order of operations has to be different.

It's all about the priority of operations.


In fact, some Greek guy said that Pi=66/21

 
C-4 писал(а) >>
Is it really clear to you the mechanism of calculating Pi number in this program, since you don't think there is anything special about it? How does this program calculate pi, by what method, how does it work? Personally, I get my balls for rollers when I see a set of such X[,%,d,],;,^,,+,-,! symbols.

Languages should be written in such a way that programmers feel comfortable and easy to work with. And the number Pi should be set as a constant. When I wrote modules in VB for my technical calculations, I put there everything from number e to Faraday's number, in order not to bother :)

-

Here's an example of what I've done for VB:

-

Dim x1...x100 As integer 'declares 100 variables from x1 to x100 at once;

Х! X' calculates the factorial of x;

x+5% 'operation with a percentage of a number;

Dim x1(double, integer) As komplex'declares a complex number;

etc.

Reason: