Log in

View Full Version : Slope equation script help



ZaSz
10-26-2008, 08:49 PM
Thank you in advance. I just need help doing the 2 cord equation. 1 cord works like a charm

procedure slope;
var
q,slopes,x1,y1,x2,y2,xs,ys,b2s,m1s,slopes,alls : integer;
b2,m1,slopess,all:extended;
begin
q := strtoint(readln('Type 1 or 2 for the following:(1: 1 cord, 2: 2 cord)'));
if q = 1 then
begin
slopes := strtoint(readln('What is the slope of the line?'));
x1 := strtoint(readln('What is the x cord?'));
y1 := strtoint(readln('What is the y cord?'));
m1 := slopes * x1;
if m1 < 0 then
begin
q := 999;
b2 := y1 + m1;
end;
if m1 > 0 then
begin
q := 99;
b2 := y1 - m1;
end;
if (q = 999) then
begin
writeln('The equation: y = '+inttostr(slopes)+'x '+floattostr(b2));
end;
if (q = 99) then
begin
writeln('The equation: y = '+inttostr(slopes)+'x '+floattostr(b2));
end;
end;
if q = 2 then
begin
x1 := strtoint(readln('What is the first x cord?'));
y1 := strtoint(readln('What is the first y cord?'));
x2 := strtoint(readln('What is the second x cord?'));
y2 := strtoint(readln('What is the second y cord?'));
ys := y1 - y2;
xs := x1 - x2;
all := ys / xs;
slopess := all;
m1 := all * x1;
alls := ys / xs;
slopes := alls;
m1s := alls * x1;
if m1 < 0 then
begin
q := 999;
b2 := y1 + m1;
end;
if m1 > 0 then
begin
q := 99;
b2 := y1 - m1;
end;
if (q = 999) then
begin
writeln('The equation: y = '+floattostr(slopess)+'x '+floattostr(b2));
end;
if (q = 99) then
begin
writeln('The equation: y = '+floattostr(slopess)+'x '+floattostr(b2));
end;
// This part is incase number is a whole number?
if m1s < 0 then
begin
q := 999;
b2s := y1 + m1s;
end;
if m1s > 0 then
begin
q := 99;
b2s := y1 - m1s;
end;
if (q = 999) then
begin
writeln('The equation: y = '+inttostr(slopes)+'x '+inttostr(b2s));
end;
if (q = 99) then
begin
writeln('The equation: y = '+inttostr(slopes)+'x '+inttostr(b2s));
end;
end;
end;

Brain
10-26-2008, 08:56 PM
Can't you just use excel for this?

Maybe?

ZaSz
10-26-2008, 09:05 PM
This is just a small part of my script, im making a massive math script to sell to my friends. And to the younger kids who shall get these problems next year.

Brain
10-26-2008, 09:18 PM
lol, so you are just giving them a script to do their homework xD

Alright, I'm done spamming your thread, I'll let someone come in here and help you :p

Buckleyindahouse
10-26-2008, 09:20 PM
Slope is that rise over run thing right?
If so, their is no absolutely need for a script for that shit, All you do is count up to the next point and over to the point and there you go

Rise
-
Run

if im wrong, then forget this lol.

ZaSz
10-26-2008, 09:22 PM
@Buck - this is for if your given a cordinate(s) + (possibly slope if only 1 cord) you get the equation...

Edit:Even tho i got no help I changed a few lines and somehow got fixed.

TravisV10
10-26-2008, 09:40 PM
The parent graph for a linear equation is y = mx + b.
M is your slope AKA rate of change. B is your y-intercept. Y-intercept is the number you start off with on the y axis before graphing.

The equation for slope is:
m = (y[1] - y[2]) / (x[1] - x[2])

All you need to do is replace the variables. This is a really easy thing to make if I'm not mistaken.

Oh btw, we learned terms at the beginning of this year and when i searched google for "subscripts", they relate it to arrays which I should have made a connection to a longgg time ago! :duh:

EDIT: Oh yeah, to get the y-intercept you find the y value when x is at zero. So do a for statement with the value closest to zero and subtract 1 from the y until its at zero. I could explain an equation for this but its the weekend and Im just tired. You'll get it

EDIT: Apparently you already get this so just ignore my message XD