> D Yazbek <dyaz...@optushome.com.au> wrote:

> [...]

> > CONST gridx=10;

> > gridy=10;

> > FUNCTION f(x:real):real;

> > BEGIN

> > f:=(10*x*x*x)+3*sqr(x)+2*x+5;

> > END;

> > VAR gd,gm,mx,my,i:integer;

> > x,y:real;

> > BEGIN

> [init graph and draw axes]

> > mx:=getmaxX DIV 2; {finds center x co-ord}

> > my:=getmaxY DIV 2; {finds center y co-ord}

> It would be best to have this *before* you draw the axes, and use these

> numbers for drawing the axes. That way if you decide you want to use a

> different mode you don't have to go and change all your hardcoded

> parameters.

> > x:=(-my*gridx)/my; {sets starting x point}

> This is clearly wrong, since its effect is to set x to -gridx, i.e. -10.

> Assuming you want to set x to the first value appearing on screen, it

> should be either "x := -mx / gridx" or "x := -mx*gridx" - you're using

gridx

> and gridy in inconsistent ways (more on that later).

> > y:=(f(x)*my)/gridy; {sets starting y point}

> You should use x and y in the same context. If you are using x as an

> argument to f, you are considering x to be the real (mathematical) value

of

> the point you want, so you should just have y as f(x). This formula also

> doesn't seem to make much sense. You are effectively multiplying y by

23.9.

> > moveto(mx-my,my-trunc(y));

> I don't think you want mx-my here.

> > setcolor(15);

> > FOR i:=-my TO my DO {mx,my = (319,239) in 640*460}

> This should be "for i := -mx to mx do..."

> > BEGIN

> > x:=(i*gridx)/my; {sets the next x co-ord to plot}

> > y:=(f(x)*my)/gridy;{sets the next y co-ord to plot}

> > lineto(mx+i,my-trunc(y));{joins the x coord, with the y coord with

a

> > line}

> > END;

> Same problems here...

> You need to work out how to convert real coordinates to screen

coordinates,

> and vice versa. Also, what are you intending "gridx" and "gridy" for? As

> you're using it, the x axis has 10 pixels per unit, while the y axis has

0.1

> pixels per unit (i.e 10 units per pixel). This is confusing. Do you

actually

> want a domain of (-32, 32) and a range of (-2400, 2400)? [This may be

> reasonable for the problem...] If so, use gridx = 10 and gridy = 0.1 or

the

> reverse, and adjust your formulae appropriately.

> Your main loop should look something like this:

> for i := -mx to mx do

> begin

> x := i / gridx;

> y := f(x);

> screenx := mx + i; {simpler than round(mx + x * gridx)}

> screeny := round(my - y * gridy);

> lineto(screenx, screeny);

> end;

> You can get your first coordinate by duplicating this for i = -mx, i.e.

> (with some simplifications):

> screenx := 0;

> y := f(-mx / gridx);

> screeny := round(my - y * gridy);

> moveto(screenx, screeny);

> Here I've assumed that gridx and gridy represent the number of pixels per

> unit, so if you make them bigger you'll be able to fit less in. I imagine

> you'd want a pretty small domain for x and a somewhat larger one for y,

> perhaps something like (-5, 5) for x and (-100, 100) for y. You could thus

> try gridx ~ 60 and gridy ~ 2.5 - adjust these for your own desires. It's

> also a good idea to include some sanity checking (i.e. make sure your

points

> will be on the screen, although in most cases the graph unit will take

care

> of this for you; also, you might want to check that a reasonable

proportion

> of the graph will actually apear on screen, and if not print a warning or

> adjust the grid spacing to suit).

> Anyway, this should clear up your problems; see how you go.

> --

> ______________________________________________________________________

> The Scarlet Manuka, | Nitpickers' Party motto:

> Pratchett Quoter At Large, | "He who guards his lips guards his

> First Prophet of Bonni, is: | soul, but he who speaks rashly will

> sa...@maths.uwa.edu.au | come to ruin." -- Proverbs 13:3

> ______________________________|_______________________________________