Lines Help
Author |
Message |
justin_lim222
|
Posted: Sat Jun 04, 2011 6:48 pm Post subject: Lines Help |
|
|
What is it you are trying to achieve?
I need to plot equations on my graph.
What is the problem you are having?
When trying to plot parabolas, the dots do not connect, they are too far away. And how can I plot y = sin(x)
(I'm only in Gr.9, this math is a little confusing :/
These are the equations I need to plot
(i) y = 2x-3
(ii) y = x^2
(iii) y = -x^2 + x - 2
(iv) y = sin(x)
And lastly, how can I find the points of intersections for these lines?
Thanks so much
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
import GUI
%Defines common variables
var y1, y2, x1, x2 : int
var font1, font2, font3 : int
var numb : int
var numbstr : string
var xposcord, yposcord, xnegcord, ynegcord : int
%Defines fonts
font1 := Font.New ("tahoma:7:bold")
font2 := Font.New ("tahoma:11:bold")
font3 := Font.New ("tahome:6:bold")
%Sets screen size
setscreen ("graphics:870;670, nobuttonbar")
%Starting points for grid lines
y1 := maxy div 2
y2 := maxy div 2
x1 := (maxx - 200) div 2
x2 := (maxx - 200) div 2
%Horizontal grid lines
for i : 1 .. 22
Draw.Line (20, y1, 648, y1, grey)
y1 := y1 + 15
Draw.Line (20, y2, 648, y2, grey)
y2 := y2 - 15
end for
%Vertical grid lines
for i : 1 .. 22
Draw.Line (x1, 20, x1, maxy - 20, grey)
x1 := x1 + 15
Draw.Line (x2, 20, x2, maxy - 20, grey)
x2 := x2 - 15
end for
%Labels and axes
Draw.ThickLine ((maxx - 200) div 2, 22, (maxx - 200) div 2, maxy - 22, 5, black)
Draw.ThickLine (22, maxy div 2, 648, maxy div 2, 5, black)
%Font.Draw ("(0,0)", 340, maxy div 2 + 8, font1, black)
Font.Draw ("y", (maxx - 206) div 2, maxy - 10, font2, black)
Font.Draw ("X", 5, maxy div 2 - 5, font2, black)
%Postive x coordinate labels
numb := 1
xposcord := (maxx - 200) div 2 + 13
for i : 1 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, xposcord, maxy div 2 - 10, font3, black)
xposcord + = 15
numb + = 1
end for
%Negative x coordinate labels
numb := - 1
xnegcord := (maxx - 200) div 2 - 20
for i : 1 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, xnegcord, maxy div 2 - 10, font3, black)
xnegcord - = 15
numb - = 1
end for
%Postive y coordinate labels
numb := 1
yposcord := maxy div 2 + 13
for i : 1 .. 9
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 9, yposcord, font3, black)
yposcord + = 15
numb + = 1
end for
%Postive y coordinate labels (To make them aligned)
for i : 10 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 12, yposcord, font3, black)
yposcord + = 15
numb + = 1
end for
%Negative y coordinate labels
numb := - 1
ynegcord := maxy div 2 - 17
for i : 1 .. 9
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 11, ynegcord, font3, black)
ynegcord - = 15
numb - = 1
end for
%Negative y coordinate labels (To make them aligned)
for i : 10 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 15, ynegcord, font3, black)
ynegcord - = 15
numb - = 1
end for
%y = 2x - 3
procedure i
for x : - 155 .. 160
Draw.Dot (x + ((maxx - 200) div 2), ((2 * x ) - 3) + (maxy div 2), black)
end for
end i
procedure ii
for x : - 315 .. 315
Draw.Dot (x + ((maxx - 200) div 2), (x ** 2) + (maxy div 2), black)
end for
end ii
procedure iii
for x : - 315 .. 315
Draw.Dot (x + ((maxx - 200) div 2), ((-x ** 2) + x - 2) + (maxy div 2), black)
end for
end iii
var equationi := GUI.CreateButton (maxx - 150, maxy div 2 + 50, 105, "y=2x - 3", i )
var equationii := GUI.CreateButton (maxx - 150, maxy div 2 + 25, 105, "y=x**2", ii )
var equationiii := GUI.CreateButton (maxx - 150, maxy div 2 + 0, 105, "y=-x**2+x-2", iii )
loop
exit when GUI.ProcessEvent
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Badsniper
|
Posted: Sat Jun 04, 2011 7:23 pm Post subject: Re: Lines Help |
|
|
It's pretty good, except your equations don't work.
When you graph the first one, the b (y-intercept) should be at -3, but it ends up at 0.
To fix this I simply added a multiplier to your draw dot... And changed it to draw fill oval, because it's too hard to see.
Turing: |
procedure i
for x : - 155 .. 160
Draw.FillOval ((x * 15) + (maxx - 200) div 2, ((2 * x ) - 3) * 15 + (maxy div 2), 3, 3, black)
% The x and y values are multiplied by 15 because that's how far apart your lines are
% Also, draw dot is too hard to see, so I change it to draw oval.
end for
end i
|
|
|
|
|
|
|
|
|