Recent

Author Topic: How can I write this formula in Lazarus?  (Read 2216 times)

lulZghost

  • Guest
How can I write this formula in Lazarus?
« on: January 16, 2019, 02:20:36 pm »
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

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How can I write this formula in Lazarus?
« Reply #1 on: January 16, 2019, 03:10:09 pm »
This, if I did it right:
Code: Pascal  [Select][+][-]
  1. var i, k, N: Integer;       {n->i}
  2.     x, Y: array of Double;  {X->Y}
  3. begin
  4.   SetLength(Y, N);
  5.   for k:=0 to N-1 do
  6.     begin
  7.       Y[k]:=0;
  8.       for i:=0 to N-1 do
  9.         Y[k]:=Y[k]+x[i]*cos(pi*k*(i+0.5)/N)
  10.     end;
  11. 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: How can I write this formula in Lazarus?
« Reply #2 on: January 16, 2019, 07:56:22 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.
That's another reason for use long variable names.  The main one is to know what contains each.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How can I write this formula in Lazarus?
« Reply #3 on: January 16, 2019, 08:35:06 pm »
It's not so bad in this example. Two loop variables (i, k) count (N) and two arrays (input X and output Y).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

furious programming

  • Hero Member
  • *****
  • Posts: 852
Re: How can I write this formula in Lazarus?
« Reply #4 on: January 16, 2019, 09:00:13 pm »
[…] and two arrays (input X and output Y).

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).
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How can I write this formula in Lazarus?
« Reply #5 on: January 16, 2019, 10:52:28 pm »
yeah but, since I work with PLC's that use X as inputs and Y as outputs it kind of flows with my
mentality ! :P
The only true wisdom is knowing you know nothing

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: How can I write this formula in Lazarus?
« Reply #6 on: January 17, 2019, 03:22:26 pm »
yeah but, since I work with PLC's that use X as inputs and Y as outputs it kind of flows with my
mentality ! :P
Also is the math way for mathematical formulae
Quote
y = ax^2 + bx + c

 

TinyPortal © 2005-2018