Results 1 to 6 of 6

Thread: Math Question!

  1. #1
    Join Date
    Apr 2007
    Posts
    2,593
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Math Question!

    Ok. I made a function that uses Sqrt, and a few others. The question is, how, when using other numbers, multiplication, division, and addition, does it come out to be the same result?

    Example:
    Code:
    Successfully compiled (61 ms)
    Original number : 81
    Number after Result := (((Result + Result) + 5) / 2) - 2.5; : 9
    Successfully executed
    Here's the actual script.
    SCAR Code:
    program SqrtEx;

    function SqrtEx(num: Integer): Extended;
    begin
      WriteLn('Original number : ' + IntToStr(num));
      Result := Sqrt(num);
      Result := (((Result + Result) + 5) / 2) - 2.5;
      WriteLn('Number after Result := (((Result + Result) + 5) / 2) - 2.5; : ' + FloatToStr(Result));
    end;


    begin
    SqrtEx(81);
    end.

  2. #2
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Algebra my good friend helps explain it.
    Result + Result + 5 := 2 * Result + 5;
    2 * Result + 5 / 2 := Result + 2.5;
    Result + 2.5 - 2.5 := Result;

    All in all, this function does nothing other than Sqrt

    edit:
    if nielsie95 = fail then
    Writeln('=p');
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  3. #3
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Result := Sqrt(num);
    Result := (((Result + Result) + 5) / 2) - 2.5;

    You first calculate the Sqrt of the number. Then you do Number * 2 + 5. When you divide by two, you get the number/2 + 5/2, which is number + 2,5. So when you do number - 2,5 you'll get the same number as what you started with, which is the sqrt.

    EDIT: aw, mixster beat me
    Hup Holland Hup!

  4. #4
    Join Date
    Apr 2007
    Posts
    2,593
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh. Lol. I know algebra, but I thought the way I had the parenthesis aligned changed it. Here's how I thought it would go:

    Let's say the original number was 81.
    Code:
    Result := Sqrt(81);
    Result := 9;
    ((Result + Result) + 5) / 2) - 2.5
    (18 + 5) / 2) - 2.5
    (23 / 2) - 2.5
    11.5 - 2.5
    9
    Am I right?

  5. #5
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    More or less, that's the way it does it.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  6. #6
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    This is how i calculate Sqrt

    works up to a 1000...

    SCAR Code:
    program new;
    var Pn: array [1..1000] of Extended;


    procedure LoadSqrt;
    var i: Integer;
    begin
     for i := 1 to 1000 do
       pn[i] := I * I;
    end;


    function sqrt2(x: Extended): Extended;
    var I, N: Integer;
        e1, e2, e3: extended;
    begin
      for i:= 1 to 1000 do
       if (pn[i] > x) then
       begin
           n := i;
           break;
       end;

      e1 := x / n;
      e2 := (e1 + n) div 2;

      while (abs(sqr(e2) - x) > 0.0000001) do
      begin
        e3 := (x / e2)
        e2 := (e2 + e3) / 2;
      end;

      Result := e2;
    end;


    var k: Integer;
    begin
    LoadSqrt;
    for k:= 1 to 100 do
     Writeln(Floattostr(sqrt2(k)));
     
    end.
    Co Founder of https://www.tagcandy.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Math Help!
    By I Karma I in forum OSR Help
    Replies: 8
    Last Post: 05-31-2007, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •