Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB script that calculates how many positive numbers that are less th

ID: 3674629 • Letter: W

Question

Write a MATLAB script that calculates how many positive numbers that are less than one million are not divisible by 2, 3, 5 or 7 using
a. a for-loop.
b. a while-loop.
c. a vector de nition followed by a single vectorized statement.

part 2

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Given the initial rst two numbers, each number in the sequence is de ned as the summation of the previous
two numbers.
a. Write a MATLAB script that calculate and print the rst n Fibonacci numbers using a loop of your choice.
Set n = 20 in your script and submit this as example output.
b. Explain why it is dicult to create the Fibonacci numbers using a vectorized command

Explanation / Answer

Part 1:

count=0;
for i=1:999999
if(mod(i,210)==0)
count=count+1;
end
end
disp(count);

count=0;
i=1;
while(i<999999)
if(mod(i,210)==0)
count=count+1;
end
end
disp(count);

Part 2:

function [ ] = fibo( n )
a=1;
b=0;
i=1;
while(i<=n)
c=a+b;
disp(c);
a=b;
b=c;
i=i+1;
end
end

Result:

>> fibo(20)
1

1

2

3

5

8

13

21

34

55

89

144

233

377

610

987

1597

2584

4181

6765

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote