Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Alex

Posts: 14
Registered: 12/18/13
Re: Even/Odd polynomial
Posted: Dec 20, 2013 3:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> % 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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.