Forum > General
How can I write this formula in Lazarus?
lulZghost:
I want to demonstrate the JPEG compression with an own example in Lazarus ... https://i.gyazo.com/22ecedb07ffd511a06fbd3841e773eb3.png this is the formula I need ... it's the DCTII.
Blaazen:
This, if I did it right:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var i, k, N: Integer; {n->i} x, Y: array of Double; {X->Y}begin SetLength(Y, N); for k:=0 to N-1 do begin Y[k]:=0; for i:=0 to N-1 do Y[k]:=Y[k]+x[i]*cos(pi*k*(i+0.5)/N) end;end;Note that Pascal is not case sensitive, so you cannot have "x" and "X" or "n" and "N" in one formula. Therefore, I used "i" instead of "n" and "Y" instead of "X".
Also, you need to initialize count N and array x.
Ñuño_Martínez:
--- Quote from: Blaazen on January 16, 2019, 03:10:09 pm ---Note that Pascal is not case sensitive, so you cannot have "x" and "X" or "n" and "N" in one formula. Therefore, I used "i" instead of "n" and "Y" instead of "X".
Also, you need to initialize count N and array x.
--- End quote ---
That's another reason for use long variable names. The main one is to know what contains each.
Blaazen:
It's not so bad in this example. Two loop variables (i, k) count (N) and two arrays (input X and output Y).
furious programming:
--- Quote from: Blaazen on January 16, 2019, 08:35:06 pm ---[…] and two arrays (input X and output Y).
--- End quote ---
X and Y are mainly used to store coordinates, which in this case is misleading.
If we have two arrays, one for input and for output, they can be simply called Input and Output (in case of parameters, AInput and AOutput).
Navigation
[0] Message Index
[#] Next page