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

Hi..pls help me to do these ..Thank you 2. Write MATLAB scripts for the followin

ID: 3910865 • Letter: H

Question

Hi..pls help me to do these ..Thank you

2. Write MATLAB scripts for the following a. To accept two numbers from the user, Display all prime numbers between these two numbers. (6 Marks) b. To accept two numbers from the user and display perfect numbers between these two numbers. (6 Marks) c. To accept two numbers from the user and display Armstrong number between these numbers. (6 Marks) Design an x-y plot for the following where the values of x are from O to 20TT with a spacing of TT/100. 3. a. y x.sin(x) b. z x.cos(x) c. Convert the above 2D into a 3D plot using z as the third axis (2 Marks) (2 Marks) (2 Marks)

Explanation / Answer

% taking user input
a = input("Enter first number: ");
b = input("Enter last number: ");

% for prime numbers
n = a : b;
p = isprime(n);
n(p)

Output

Enter first number: 30
Enter last number: 90
ans =

31 37 41 43 47 53 59 61 67 71 73 79 83 89

% taking user input
a =input('Enter first number: ');
b =input('Enter last number: ');

% check for perfect number
for k = a : b
fs = 1:k;
facts =fs(rem(k,fs)==0) ;
facts(end) = [] ;
if sum(facts) == k
disp(k)
end
end

Output

Enter first number: 2
Enter last number: 2000
6
28
496

% taking user input
a =input('Enter first number: ');
b =input('Enter last number: ');

% check for armstrong number
for k = a : b
n = num2str(k);
total = 0;
for i = 1: length(n)
total = total+ (str2num(n(i)))^3;
end
  
if total == str2num(n)
disp(k)
end
end

Output

Enter first number: 2
Enter last number: 2000
153
370
371
407

% taking user input
a = input("Enter first number: ");
b = input("Enter last number: ");

% for prime numbers
n = a : b;
p = isprime(n);
n(p)

Output

Enter first number: 30
Enter last number: 90
ans =

31 37 41 43 47 53 59 61 67 71 73 79 83 89

% taking user input
a =input('Enter first number: ');
b =input('Enter last number: ');

% check for perfect number
for k = a : b
fs = 1:k;
facts =fs(rem(k,fs)==0) ;
facts(end) = [] ;
if sum(facts) == k
disp(k)
end
end

Output

Enter first number: 2
Enter last number: 2000
6
28
496

% taking user input
a =input('Enter first number: ');
b =input('Enter last number: ');

% check for armstrong number
for k = a : b
n = num2str(k);
total = 0;
for i = 1: length(n)
total = total+ (str2num(n(i)))^3;
end
  
if total == str2num(n)
disp(k)
end
end

Output

Enter first number: 2
Enter last number: 2000
153
370
371
407

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