Results 1 to 2 of 2

Thread: Maths Tools

  1. #1
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Maths Tools

    Well, my rtard of a maths teacher (I won't get into that now) likes to assign a lot of the same-ish questions, over and over. The flavour of this week is apparently finding the y-intercept of a linear relation given the slope and a point that lies on the line.

    Maybe in future versions I'll have different permutations, such as slope and y-intercept given two points, or points given slope and a y-intercept.

    Enjoy, rate/hate.

    SCAR Code:
    program New;

    var
      Slopem, InputSlope : string;
      TheSlope, xBym, XVal, YVal, InvX, LeftSide, YInt, Num, Denom : extended;

      Equation : string;
      Rational, Negative : boolean;

    procedure CalculateInput;
    begin
      XVal := StrToFloat(Readln('X coordinate?')); //StrToFloat(LabeledEdit1.text);
      YVal := StrToFloat(Readln('Y coordinate?')); //StrToFloat(LabeledEdit2.text);
      InputSlope := Readln('Slope? (write rational numbers as a/b'); //Slope.text;
    end;

    procedure DoIt;
    var
      XVal2,YVal2 : extended;
    begin
    CalculateInput;
    Equation := 'y = '+InputSlope+' x + b';
    //writeln(replace(Equation,' ',''));
    Equation := replace(Equation,' ','');
    slopem := copy(Equation,pos('=',Equation)+1,(Pos('x',Equation) - Pos('=',Equation))-1);
    //Writeln(Slopem);
    if(Pos('/',Slopem) > 0) then Rational := True;
    if(not Rational) then
    begin
      //Writeln(Slopem);
      TheSlope := StrToFloat(Slopem);
      xBym := XVal * TheSlope;
      //Writeln(FloatToStr(xBym));
      InvX := xBym * -1;
      //Writeln(FloatToStr(InvX));
      LeftSide := YVal + InvX;
      //Memo1.lines.add('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.');
      GetApplication.MessageBox('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.','Result',1);
    end else
    begin
      Num := StrToFloat(Copy(Slopem,0,Pos('/',Slopem)-1));
      Denom := StrToFloat(Copy(Slopem,Pos('/',Slopem)+1,1));
      YVal2 := YVal * Denom;
      XVal2 := XVal * Denom;
      xBym := XVal * Num;
      InvX := xBym * -1;
      LeftSide := YVal + InvX;
      YInt := LeftSide * Num;
      //Writeln(FloatToStr(YInt));
      GetApplication.MessageBox('The line with slope '+slopem+' and with the point ('+FloatToStr(XVal)+','+FloatToStr(YVal)+') has a y-intercept of '+FloatToStr(LeftSide)+'.','Result',1);
    end;
    end;

    begin
    DoIt;
    end.

  2. #2
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Are you in my Math class? I am learning about like the same thing right now...
    Weird o_O...

    Nice job anyways, maybe you should print the script out and show to her, get some extra credit


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Maths Function?
    By Rich in forum OSR Help
    Replies: 9
    Last Post: 11-09-2008, 05:00 PM
  2. help plz with homework [maths]
    By RudeBoiAlex in forum News and General
    Replies: 5
    Last Post: 06-05-2007, 11:41 PM

Posting Permissions

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