I'm trying to write a custom function but it isn't returning any output.
Here's my code so far:
Options[Alternate] = {AlternationType -> AlternationPlusMinus};
Alternate[Terms_, Exponent_, OptionsPattern[]] := (
tmpSet = {};
If[OptionValue[AlternationType] == AlternationPlusMinus,
Do[If[Mod[counter, 2] != 0,
AppendTo[tmpSet, (counter^Exponent) - 1] AppendTo[
tmpSet, (counter^Exponent) + 1]], {counter, Terms}],
Do[If[Mod[counter, 2] != 0,
AppendTo[tmpSet, (counter^Exponent) + 1] AppendTo[
tmpSet, (counter^Exponent) - 1]], {counter, Terms}]];
Return[Expand[InterpolatingPolynomial[tmpSet, x]]];
);
Alternate[20, 2]
When I execute it, no output block is even generated, let alone any error messages or warnings, is there any way to fix it?
Thanks.
(Thread::tdlen: Objects of unequal length in {0} {0,2} cannot be combined. >>)
. Have you tried this in a fresh kernel? Also, you are not localizingtmpSet
. Try wrapping your function withModule
. Also, tryFold
instead ofDo
andReturn
. $\endgroup$ – Verbeia Jul 1 '12 at 21:55