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:
OR
OR