Search This Blog

#Day100#100DaysChallenge- Matlab Loops |Sum of Even Fibonacci Series -Matlab Cody

#Day100-Sum of Even Fibonacci Series-Matlab Cody

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed the input value, find the sum of the even-valued terms.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab Code:

function y = euler002(x)

t1=1;

t2=2;

y=0;

      while t1<=x

      yy=t1;

      temp=t1;

      t1=t2;

      t2=temp+t2;

      if rem(yy,2)==0

          y=y+yy;        

      end

      end

end

Sample Input and Output

>> x =597455000 y_correct = 350704366; assert(isequal(euler002(x),y_correct))
Test Suite -Pass.

Click here for video Description



6 comments:

  1. Replies
    1. Adobe Dreamweaver is a web development tool that allows users to write code and view front-end changes directly from the app in real time. This makes coding faster and simpler than ever before. Dreamweaver is highly versatile and supports an extensive range of languages, making it a powerful tool that can meet the needs of any user. http://www.beecracked.com/adobe-dreamweaver-cc/

      Delete
  2. MnM Tech solutions is a house full of highly skilled individuals having expertise in their individual fields provides innovative wide range of digital solutions Globally.

    ReplyDelete
  3. Adobe Dreamweaver is a web development tool that allows users to write code and view front-end changes directly from the app in real time. This makes coding faster and simpler than ever before. Dreamweaver is highly versatile and supports an extensive range of languages, making it a powerful tool that can meet the needs of any user. http://www.beecracked.com/adobe-dreamweaver-cc/

    ReplyDelete

MATLAB