Function Finds the Prime Factorization of An Integer Greater than 1

12 ビュー (過去 30 日間)
Sophie Culhane
Sophie Culhane 2020 年 10 月 28 日
コメント済み: Sophie Culhane 2020 年 10 月 29 日
My task is to create a function that finds the prime factorization of an integer greater than 1. n is a positive integer and v is a row vector containing the prime factorization of n given in order including repetitions. (primes(k) returns a row vector of the primes 2 to k). I understand that I am to create a program that takes a number n such as 600 and produces a row vector v that contains the prime factorization of the number such as v = [2 2 2 3 5 ]. I know I will need to use some rounding techniques like the 'fix' command. I am asking for help on how begin making this program as I barely have anything and am lost in how to continue. Here is what I have:
function v = ex5(n)
%
%
v = zeros(1, %number of primes in n)
if n/2 == fix(n/2)
% n must be divided by 2 and keep dividing until n/2 ~= fix(n/2)
% n must be divided by 3 ...
% n must be divided by 5 ...
% keep dividing by the primes
% store all the primes divisible by n in vector v
end
I understand this is a rough outline of my program. Thank you in advance for the help.

採用された回答

Jon
Jon 2020 年 10 月 28 日
編集済み: Jon 2020 年 10 月 28 日
The matlab factor command does it one line. But maybe you have to do it yourself for a homework exercise? For example
f = factor(600)
f =
2 2 2 3 5 5
  7 件のコメント
Sophie Culhane
Sophie Culhane 2020 年 10 月 29 日
Thank you for the help. I believe I have developed a program that works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecial Functions についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by