Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Even/Odd polynomial
Replies: 5   Last Post: Dec 22, 2013 6:23 PM

 Messages: [ Previous | Next ]
 Alex Posts: 14 Registered: 12/18/13
Re: Even/Odd polynomial
Posted: Dec 20, 2013 3:23 PM

> % One obvious way is to use a function call. Something like:
>
> [ae,ao] = myOddEven(a);
> [be,bo] = myOddEven(b);
>
> function [ce,co] = myOddEven(c)
> ce = [];
> co = [];
> if mod(length(c),2) == 0
> for i = 1: length(c)
> if mod(i,2) == 0
> ce = [ce c(i)];
> else
> co = [ao a(i)];
> end
> end
>
> else
> for i = 1: length(c)
> if mod(i,2) == 0
> co = [co c(i)];
> else
> ce = [ce c(i)];
> end
> end
> end
>
> % Now, think about what is in the function.
> % All you are doing is picking every other element of c
> % with some minor variations depending on length of c
> % being odd or even. So, instead of the if statements,
> % You could do something like:
>
> co = c(1:2:end);
> ce = c(2:2:end);
>
> % I'll leave the rest to you.

Sorry but i didn't understand.

Date Subject Author
12/19/13 Alex
12/19/13 Curious
12/20/13 Alex
12/20/13 Curious
12/21/13 Alex
12/22/13 Curious