
-----------------------------------
varman
Wed Feb 01, 2012 8:30 pm

How do you compare a bunch of different numbers from a loop?
-----------------------------------
What is it you are trying to achieve?
I need to compare a bunch of different numbers from a loop in order to show which gave the smallest output of an equation.


What is the problem you are having?
I don't know how to compare the numbers. Basically, the question asks to compute values of the function f(x) = 3x2 ? 2x+1 in steps of 0.1 between x=0 and x=1 inclusive and find the
value of x for which f(x) is a minimum. So I am having trouble with the last part.


Describe what you have tried to solve this problem
I tried to think of a solution but couldn't.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




 0.9
end loop
if fx < fx then
put "The answer was the smallest when f(x) was " 
end if
>



Please specify what version of Turing you are using
4.1

-----------------------------------
Dreadnought
Wed Feb 01, 2012 9:36 pm

Re: How do you compare a bunch of different numbers from a loop?
-----------------------------------
Perhaps you could keep track of the minimum value as you iterate over your input. Then for each input, you can compare the value of the function to the minimum.

-----------------------------------
varman
Wed Feb 01, 2012 10:23 pm

RE:How do you compare a bunch of different numbers from a loop?
-----------------------------------
But there is no input. Everything happens without the user typing in anything

-----------------------------------
DemonWasp
Wed Feb 01, 2012 10:48 pm

RE:How do you compare a bunch of different numbers from a loop?
-----------------------------------
So...keep track of the minimum value as you loop over the values of x.

-----------------------------------
varman
Wed Feb 01, 2012 11:26 pm

RE:How do you compare a bunch of different numbers from a loop?
-----------------------------------
How do I do that? Is there a variable automatically assigned to every value of x?

-----------------------------------
DemonWasp
Thu Feb 02, 2012 9:12 am

RE:How do you compare a bunch of different numbers from a loop?
-----------------------------------
Well, right now you have the value of x (which increases by 0.1 and so on) in a variable called 'fx' (not sure why). You have the value of f(x), which I would ordinarily call 'f', as 'ans'.

-----------------------------------
Velocity
Tue Feb 07, 2012 5:34 pm

RE:How do you compare a bunch of different numbers from a loop?
-----------------------------------
so at the beginning of the loop state the new fx value so that it tracks it ever time it executes the loop
