Recent

Author Topic: Equation in Lazarus  (Read 11191 times)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Equation in Lazarus
« Reply #15 on: October 20, 2014, 05:24:23 pm »
Quote
I still have not fully understood how these loops work.
Look at a simplified version of your code:

Code: [Select]
  dtime := 1;
  while (dtime <= 3600) do begin
    something;
    dtime := dtime;
  end;
  code_after_loop;
This is the loop. It starts with dtime = 1 - you had set this value immediately before the program reaches the "while " instruction. This value is smaller than 3600. Therefore the program enters the code block after "while" and "end" - the condition after "while" must be true, otherwise the program jumps to the end of the loop ("end") - http://wiki.freepascal.org/WHILE..DO

Then "something" is calculated using this dtime value. At the end of the calculation dtime is incremented by 1, and the calculation is repeated.

With every pass through the loop dtime is incremented. Eventually dtime will have the value 3601. In this case, the logical condition specified after "while" is no longer true, and the program does not longer enter the "while" part, but executes code after the loop.

Please be aware that the code that you posted does not lead to a correct solution of the differential equation. Please read my posting above.

ninaAU

  • New member
  • *
  • Posts: 9
Re: Equation in Lazarus
« Reply #16 on: October 20, 2014, 05:40:22 pm »
wp..
Unfortunately, I am not familiar with the command that you call round.
You have written:   n: = round (t max / dTime) + 1;
What does that mean?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Equation in Lazarus
« Reply #17 on: October 20, 2014, 05:43:26 pm »
Hello ninaAU, are you able to look up keywords in the context sensitive help? Press F1 when typing round.
Also searching for
round Delphi
or
round Pascal
in any search engine should give you results.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Equation in Lazarus
« Reply #18 on: October 20, 2014, 06:22:38 pm »
wp..
Unfortunately, I am not familiar with the command that you call round.
You have written:   n: = round (t max / dTime) + 1;
What does that mean?

The variable n gets gets tmax divided by dTime, rounded to the nearest integer. 1 is added to the result to avoid that n gets 0.

I think that your Delphi book is not too good. I recommend Howard Page-Clark's excellent book "Learn to Program Using Lazarus", available from blaisepascal.eu.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

 

TinyPortal © 2005-2018