| Author |
Message |
Dave54
Joined: 24 Mar 2007 Posts: 1
|
Posted: March 24, 2007 9:34 PM Post subject: A simple question |
|
|
I need help defining a function in a program I'm writing. This simple example will show my problem.
I will use "->" to stand for the "store to" arrow.
Type the following:
2*x+3 -> a
a+2 -> f(x)
f(5)
I would expect f(x) to now equal 2*x+5, so f(5) should equal 15. Instead, f(5) returns 2*x+5.
This is because f(x) is not 2*x+5. f(x) is a+2. When I ask for f(5), it plugs 5 into every x in a+2, then substitutes 2*x+3 into a. The result is 2*x+3+2, which is 2*x+5.
Is there any way to make the calculator evaluate "a" (which is 2*x+3) before storing it into f(x)?
This would be very helpful. Thank-you. |
|
| Back to top |
|
 |
mellamokb
Joined: 10 May 2007 Posts: 124
|
Posted: May 17, 2007 10:38 PM Post subject: |
|
|
Hi Dave54,
The problem with your situation is that the varible in the function ("x") does not match the variable in the expression ("a"). If the variables differ when the function is defined, the actual value will not be substituted into any variables whatsoever.
Try storing your first expression into a function rather than a variable. Then define the second function in terms of the first function, so that all of the varibles match, like this:
| Code: |
2*x+3->g(x)
g(x)+2->f(x)
|
Using these function definitions, f(5) returns 15 as desired. Hope this helps!
~ mellamokb |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
Saphic 1.5 // Theme created by Sopel
|
|