Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


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.



