How can I make Flash calculate the value of the function y= (1 - x^2)^3 where x is the user input value?
function calculate(x:Number):Number {
return Math.pow(Math.pow(1-x, 2), 3);
}
var value:Number = calculate(5);
trace(value);
I might just be tired, although I’m pretty sure that’s not it. But it appears that your calculation is wrong Matthew.
you have (1 - x)^2… it is 1 - x^2, the Exponent has more precedence than the subtraction operator
The code should be…
function calculate( x:Number ) : Number
{
return Math.pow(( 1 - (x * x)), 3);
}
var value:Number = calculate(5);
trace( value );
Another thing to think about is, multiplying two values together is much faster than making a call to the Math classes pow method to do it. I usually just multiply the two values together rather than square the single value. It’s really just preference.
I am very tired… Catch you on the flip side
_Michael
Why is there calculate (5)? I dont understand this. Is it necessary to declare variable x or can I just write ‘InputValue’ which is already declared as variable input text?