Part 2: Loops in MATLAB Problem 2 Write a MATLAB Script that prints all even num
ID: 3168155 • Letter: P
Question
Part 2: Loops in MATLAB Problem 2 Write a MATLAB Script that prints all even numbers between 1 and N. Problem 3 Write a MATLAB Script that fills a vector with descending odd numbers, starting from N Example output: 3 Problem 4: Write a MATLAB Script that fills a square matrix with ascending numbers counting from 1 to N by increments of z. If a square matrix cannot be filled with N values, display an error. Example output (for counting from 1 to N41 by z5) 1 6 11 16 21 26 31 36 41 Example output (for counting from 1 to N13 by z4) Error, you cannot count from 1 to 13 by 4's and fill a square matrix. Explanation (your code doesn't need to print this): 13 Problem 5 Write a MATLAB Script that fills a square matrix with N digits of Pi.Explanation / Answer
2)
N=input('Enter the number N = ');
for n=1:N
if mod(n,2)==0
disp(n);
end
end
OUTPUT:
Enter the number N = 45
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
3)
N=input('Enter the number N = ');
for n=N:-1:1
if mod(n,2)~=0
disp(n);
end
end
OUTUT:
Enter the number N = 13
13
11
9
7
5
3
1
4)
N=input('Enter the number N = ');
z=input('Enter the z = ');
k=1;
n=1;
while ( n <= N)
if ( n <= N)
A(k,1)=n;
else
disp('Not possibel to fill square matrix');
break;
end
if (n+z <= N)
A(k,2)=n+z;
else
disp('Not possibel to fill square matrix');
break;
end
if (n+2*z <= N)
A(k,3)=n+2*z;
else
disp('Not possibel to fill square matrix');
break;
end
k=k+1;
n=n+3*z;
end
A
OUTPUT:
Enter the number N = 41
Enter the z = 5
A =
1 6 11
16 21 26
31 36 41
Enter the number N = 13
Enter the z = 4
Not possibel to fill square matrix
A =
1 5 9
13 0 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.