Well, the function y = f(x) implies the solution. For any given input, x, to the function, f, you get an output, y.
I hope (x,y) looks familiar to you.
So now you just need to take some sample points (x values), feed them through that equation, and get the samples (y values) out. Then, for each (x,y) pair, draw a dot.
You can get more advanced from there. Advanced: drawing lines between each set of sample points to "connect" the graph; scaling and moving the graph so (0,0) is in the center of the screen; graphing multiple functions on the same axes.
TW iz Rippin
Posted: Tue Apr 03, 2012 9:57 am Post subject: Re: RE:Turing Graphing Calculator (Help)
DemonWasp @ Mon Apr 02, 2012 10:19 pm wrote:
For any given input, x, to the function, f, you get an output, y.
Oh, you didn't mean x^3, you meant x3. I figured you had typed in superscripts and they had been destroyed.
If you have multiple inputs, then your function is something like y = f(x1,x2,x3,x4,x5), which you cannot graph completely in two dimensions. If you have 5 inputs and one output, you need 6 dimensions to graph the function.
You could graph some 2D "slice" of the function (by setting 4 inputs to constants, varying one input, and graphing that one changing input against the changing output). For example, with x1 = x2 = x3 = x4 = 0, and x5 variable; then y = f(0,0,0,0,x5) = x5, which you can plot (it's a line).
These are all functions that take only one value as input (x in this case) and evaluate to different values based on the x given. You can plot f(x) vs x on a graph by letting y=f(x) and computing f(x) for many values of x.
This is basically the function f(x) = 20*x. (EDIT: why did I say "basically"? IT IS that function)
Maybe this will give you an idea of the problem (hint: think of your axes and their scale).
while I ponder this do you know how do to this in real numbers because the syntax for draw.filloval is all integer so Draw.FillOval (i, fx, 3, 3, black) wont work if I have one of the inputs as real (which it should be)
Well, lets say you want x values in increments of 0.05 between 0 and 10.
Well, what's an increment but a step of a certain size (0.05 in this case).
So we start with 0, then 0.05 then 0.1, then 0.15, etc.
Notice we can write this as 0*0.05, then 1*0.05, then 2*0.05, then 3*0.05, etc.
For 0 to 10 by 0.05, you would have 200 increments (this does not include 0 which is the starting value), so you could run a loop 200 times and simply divide the number of times it has run by 20 to get the value of x for that iteration.
Now, this brings us back, to your previous problem in a way (the scale of our axes). How do we graph (0.05, 1.25) with functions that draw at integer numbers of pixels?
Well, we can change the scale of our axes if we require. Make each increment of 0.05 in the x direction on your graph be a increment of 1 pixel on your screen (or more if you want). You can do the same with the y coordinate. Of course, use round to convert from real to integer (since 1.0 is not considered an integer).
Think of it as stretching your graph on the screen.
I understand what your saying, im just turing illiterate (first year)...
when i do like
for i : 0 .. 10 by 0.05 it says it has to be an int so idk how i can do that lol
and for the graphing of real numbers as points.
I try to do round on i sooo
code:
for i : 1 .. 9
fx := 0
fx := (text1 * (i ** 5)) + (text2 * (i ** 4)) + (text3 * (i ** 3)) + (text4 * (i ** 2)) + (text5 * i) + text6
round (fx)
Draw.FillOval (i, fx, 3, 3, black)
end for
I get an error on the round because its not a procedure and on the fill oval because its the wrong type.
P.S. Im so sorry for how bad I am at this, must be frustrating for you, but this assignment is far above my skill level (and tbh I think its the same for most of the people in my class)
P.S.S I guess what im saying is, can you help with the syntax without telling me the exact code cause I can do the math ok
Dreadnought
Posted: Wed Apr 04, 2012 2:04 am Post subject: Re: Turing Graphing Calculator (Help)
Ok. So you are right, we can't have a for loop give us real numbers directly. But, what is the difference between increments of 1 and increments of 0.05?
Well, its factor of 0.05, so we can just multiply the value incremented by the for loop by 0.05 to obtain the value we want.
Example: print 0..1 in increments of 0.05
Turing:
for i:0..20 const x := i *0.05% store the value we want (I'm using a constant to mimic the way a for loop works) put x
endfor
This is an easy way of getting around the limitation that a for loop must have integer increments. Note, that I set the upper value of the for loop manually, but you could have computed that you needed the for loop to go up to 20 by dividing 1 by 0.05 (you would have to round).
TW iz Rippin wrote:
I get an error on the round because its not a procedure and on the fill oval because its the wrong type.
Well, that is because round is a not a procedure, but a function (kinda like your f(x) function you want to graph).
Functions, are pieces of code that take one or more (or zero in rare cases) values as input (we call these arguments) and produce a value as output.
Procedures are pieces of code that can take value as input but produce no output. They generally make changes to variables, the screen or other things (since they don't have output).
The problem you are having is that procedure calls (when you ask Turing to run them) are different from function calls.
Turing:
% We call a procedure like so
procName (arg1, agr2, ...)% note that if there are no arguments we don't need brackets
% Examples of procedures are
cls% it takes no arguments, you could also call "cls ()" View.Set(SetupString)% takes a string as an argument (Ex "graphics;400:300") Draw.Oval(x ,y, xrad, yrad, <colour>)% takes five arguments of different types and draws an oval on the screen
% To call a function is similar, but it returns a value. We need to do something with that value % Either we assign the value to a variable, or we use it as an argument to some other procedure or function var varName : <type> % type could be int, real, string, etc.
varName := fcnName (arg1, arg2, ...)
% Examples of functions
var two :int:=round(1.5)% The round function rounds a real real number toward the nearest integer var tenIsBigger :int:=max(7, 10)% The max functions returns the largest of its arguments var ch :char:getchar% The getchar function takes no arguments and produces character corresponding to the key pressed by the user
% We can also do this putmax(round(1.5),1.5)% Here we round 1.5 and use that as an argument to max, and we print the result to the screen (it will be 2 in this case)
Ok, so if you're still reading this, the main idea is that functions like round produce a value and you need to do something with that value.
Since, f(x) will be a real value much of the time, we will need to use round to convert to the nearest integer if we want to use it in a procedure that accepts only integer arguments (like Draw.Oval).