1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dem82 [27]
3 years ago
15

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 te

rms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...Write a MATLAB code to find the sum of all even-numbered terms in the sequence whose values are less than or equal to 500. (Hint: You may find the built-in commands "fibonacci" and "mod" useful for this problem.)
Computers and Technology
1 answer:
Aloiza [94]3 years ago
3 0

Answer:

  1. sum = 0;
  2. n =  1;
  3. f = fibonacci(n);
  4. while f <= 500
  5.    if(mod(f,2)==0)
  6.        sum = sum + f;
  7.    end
  8.    n = n + 1;
  9.    f = fibonacci(n);    
  10. end
  11. disp(sum)

Explanation:

Firstly, let's define several variables which are necessary to hold the value of total of Fibonacci sequence, <em>sum</em>, Fibonacci index,<em> n</em> and Fibonacci term, <em>f</em> (Line 1 - 3). We can get the first Fibonacci term using the Matlab built-in function <em>fibonacci() </em>(Line 3).

Since the Fibonacci term should be less than or equal to 500, create a while condition that meet the requirement (Line 5). Within the while loop, check if the current Fibonacci term is an even number. This can be achieved by using mod() function to calculate the <em>f</em> modulus by 2 (Line 6). If the result is zero, the <em>f</em> is an even number and f value will be added with variable <em>sum</em>.

Next increment the Fibonacci index by 1 and use the same function <em>fibonacci()</em> to get the next Fibonacci term, f,  and repeat the same process as described above until the <em>f</em>  becomes bigger than 500.

At the end, display the result (Line 13). The result shall be 188.

You might be interested in
How do I write this code in java? input "Enter Your Age to Order a Beer"
Klio2033 [76]

Answer:

i dont know sorry but answer above lol

Explanation:

5 0
3 years ago
I WILL GIVE BRAINIEST ANSWER AND THANKS IF YOU ANDWER THIS QUESTION!!!!
sesenic [268]
Access: full electronic participation in society.
Commerce: electronic buying and selling of goods.
Communication: electronic exchange of information.
Literacy: process of teaching and learning about technology and the use of technology.
Etiquette: electronic standards of conduct or procedure.
Law: electronic responsibility for actions and deeds.
Rights & Responsibilities: those freedoms extended to everyone in a digital world.
Health & Wellness: physical and psychological well-being in a digital technology world.
Security (self-protection): electronic precautions to guarantee safety.

IMPORTANT
Etiquette. Students need to understand how their technology use affects others. ...
Literacy. Learning happens everywhere. ...
Rights and responsibilities. Build trust so that if something happens online, students are willing to share their problems or concerns about what has happened.
6 0
3 years ago
2.4 Code Practice: Question 1
USPshnik [31]

Answer:

num = float(input("Enter a number : "))

ab = abs(num)

sqrt = float(ab ** 0.5)

print(sqrt)

Explanation:

6 0
4 years ago
Keeping in mind the role the order of precedence plays in equations, what would Excel display as the result of the following equ
emmasim [6.3K]
The correct answer for the question that is being presented above is this one: "5.5" <span>Keeping in mind the role the order of precedence plays in equations, Excel would display as the result of the following equation? =(24+75)/(6*3): 5.5.</span>

5 0
3 years ago
What is what is a network that is easy to maintain and cheap ​
kifflom [539]

Answer:

Click at the pic above and the ans will appear.

Hope it helps :)

4 0
3 years ago
Other questions:
  • Many shops are simply plugging up their drains to keep from inadvertently violating the law and creating environmental contamina
    15·1 answer
  • While designing web pages for mobiles, the page content should be extensive such that the readers get the opportunity to explore
    5·2 answers
  • Match the spreadsheet features with their respective descriptions.
    9·2 answers
  • Which of the following was the name of the first generation of cell phone networks?
    14·1 answer
  • You have been handed a mysterious piece of data by an unknown person. Judging by his shifty eyes and maniacal laughter you don't
    12·1 answer
  • How does a computer work
    13·1 answer
  • The following is a true example of a computer: A. Toyota Camry
    12·1 answer
  • This is for C++: Using a nested for loop output the following pattern to the screen:
    12·1 answer
  • What data type would you use for a decimal number?* ​
    9·1 answer
  • O How basic blocks are identified and how the blocks are used to construct control flow graphs
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!