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
Translate each of these statements into logical expressions using predicates, quantifiers, and logical connectives. a) Something
yKpoI14uk [10]

Answer:

Let P(x) = x is in the correct place

Let Q(x) =  x is in the excellent place

R(x) denotes the tool

Explanation:

a) Something is not in the correct place.

P(x) is that x is in the correct place so negation of ¬P(x) will represent x is not in the correct place. ∃x is an existential quantifier used to represent "for some" and depicts something in the given statement. This statement can be translated into logical expression as follows:

                                                    ∃x¬P(x)

b) All tools are in the correct place and are in excellent condition.

R(x) represents the tool, P(x) represents x is in correct place and Q(x) shows x is in excellent place. ∀ is used to show that "all" tools and ∧ is used here because tools are in correct place AND are in excellent condition so it depicts both P(x) and Q(x). This statement can be translated into logical expression as follows:

                                       ∀ x ( R(x) → (P(x) ∧ Q(x))

c) Everything is in the correct place and in excellent condition.

Here P(x) represents correct place and Q(x) represents excellent condition ∀ represent all and here everything. ∧  means that both the P(x) and Q(x) exist. This statement can be translated into logical expression as follows:

                                              ∀ x (P(x) ∧ Q(x)

7 0
4 years ago
Are they going to make season two of Midori Days
Maksim231197 [3]

Answer:

No i dont think

Explanation:

6 0
3 years ago
Read 2 more answers
Assume that you are testing the Orders database introduced in Watt (2014) - Appendix C. Discuss the problems and possible conseq
madreJ [45]

Answer:

129 \frac{2}{?} 23.4. \div 164 \times 5y1 + . \\ .00487ggh

6 0
4 years ago
The _____ is the mechanism inside a computer that actually does the arithmetic and logical operations.
dimaraw [331]

Answer:

The arithmetic/logic unit

Explanation:

The arithmetic/logic unit (ALU) contains the electronic circuitry that executes all arithmetic and logical operations. The arithmetic/logic unit can perform four kinds of arithmetic operations, or mathematical calculations: addition, subtraction, multiplication, and division.

https://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading04.htm

8 0
3 years ago
Write a function call using the ebay_fee() function to determine the fee for a selling price of 15.23, storing the result in a v
Sholpan [36]

Answer:

my_fee = ebay_fee(15.23)

Explanation:

Functions are sections of a program that provide a particular outlined procedure, we call a function by writing its name followed by a pair of parenthesis, the function may be designed in a way that it accepts arguments while been called, Like the case of the ebay_fee(15.23). the number within the pair of parenthesis id the argument, and it is the data that the functions will process and return a value afterwards.

7 0
4 years ago
Other questions:
  • OSHA has authority over the employers of
    5·2 answers
  • The term median means
    9·2 answers
  • For delivering a message that is straightforward and informative, a face-to-face encounter is preferred over a technological cha
    8·1 answer
  • N, or central processing unit, is also known as the
    10·2 answers
  • A Homecoming Crossword Puzzle
    12·1 answer
  • Define ethical (include a link to the source of definition). Describe the ethical dilemma (issue) in this scenario.
    12·1 answer
  • pharmaceutical company is using blockchain to manage their supply chain. Some of their drugs must be stored at a lower temperatu
    5·2 answers
  • Your program has a loop. You want to exit the loop completely if the user guesses the correct word.
    6·2 answers
  • Write a simple program that takes in a numerator and denominator and then computes the GCD for that fraction. You can assume tha
    14·1 answer
  • What year was html released?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!