Suppose that you need to find all integers between 1 and 1000 that are divisible
ID: 3680473 • Letter: S
Question
Suppose that you need to find all integers between 1 and 1000 that are divisible by 7 and have remainder 1 when divided by 2, 3, 4, 5, and 6. Can you write a short Matlab script to do this?
Try the following (and make sure you understand each step. Copy entire code in a script file and run one statement at a time. Remove semicolons (;) to observe the outputs. You may set breakpoints in the code):
Note that setting elements of an array to an empty array, [], eliminates these elements from the original array (as demonstrated in last week's lab).
Can you alter the code above to find all integers between 1 and 1000 that are divisible by 7 and have remainder 2 when divided by 13? Hint: if you copy the code into a script file and make changes within the script it will be much easier than typing the program out each time.
How many values fit this criteria?
Explanation / Answer
modified matlab code:
n = 7:7:1000;
N = length (n );
ii=13
r = rem(n,ii) ~= 2;
n(r) = [];
N = length (n );
n
output:
ii =
13
n =
28 119 210 301 392 483 574 665 756 847 938
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.