Using Matlab Write Function Takes Relatively Small Less 100 Billion Positive Integer Input Q37060965

Using MATLAB write a function that takes a relatively small(less than 100 billion) positive integer input and outputs theprime factorization of that integer using as few built-in functionsas possible. Explain the processes with comments.


Solution


MATLAB CODE: ( prime_factors.m )

function []=prime_factors(n)
% beginning of the function %

   % checking for negative input %
   if n < 0
      
       disp(“The number cannot benegative”);
       return

   end

   % getting the vector of prime factors of the given’n’ using factor function %
   p=factor(n);

   % printing the prime factors %
   fprintf(“nThe prime factors of %d are:nn”,n);
   disp(p);

% end of the function %  
end

SCREENSHOT FOR OUTPUT:

octave: 26> prime factors (-15) The number cannot be negat ive octave: 27> prime factors (1500) The prime factors of 1500 are

octave:

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.