replace matlab function with algorithm

this is my current code. how do i replace the isperfect function to n = p1 · p2 · ... · pt
disp('Perfect numbers!');
disp('Enter two numbers(intervals)');
num1 = input('Enter num1 value: ');
num2 = input('Enter num2 value: ');
fprintf('Perfect numbers between %d and %d are: ', num1, num2);
for i = num1:num2
if isperfect(i)~=0
fprintf('%d, ',i)
end
end

댓글 수: 3

dpb
dpb 2015년 5월 27일
I dunno...what do you think is a "perfect" number?
Adam
Adam 2015년 5월 27일
isperfect is not a builtin Matlab function so I don't see what the problem is. You can program an algorithm in a function called isperfect just like any other function.
Indeed, if such a function doesn't exist on your system then that code will not run anyway.
Josaiah Ang
Josaiah Ang 2015년 5월 27일
thank Adam. thanks for the clarification. in this case, is something wrong with the code for me to get the perfect number?

댓글을 달려면 로그인하십시오.

답변 (2개)

Al Dente
Al Dente 2015년 5월 27일
편집: Al Dente 2015년 5월 27일

0 개 추천

your tags say prime, so I assume you want to find out prime numbers:
isprime(i)~=0
would that be the answer to your question?

댓글 수: 1

Josaiah Ang
Josaiah Ang 2015년 5월 27일
sorry i tag wrongly.
i want to display the perfect numbers between the 2 input by user.

댓글을 달려면 로그인하십시오.

Roger Stafford
Roger Stafford 2015년 5월 27일

0 개 추천

I have given you a pretty good hint four days ago at solving your problem in the #218267 Answers thread. Why don't you try using it?

댓글 수: 3

Josaiah Ang
Josaiah Ang 2015년 5월 27일
Thank you Roger. Appreciate the hint you have given. As I just picking up matlab 2 weeks ago, Im kinda lost with the hint you have given. Apologies for that obvious hint you have given.
In all your remarks, Josaiah Ang, there is no evidence that you actually understand the meaning of a perfect number. If that is true, getting an understanding should be your next move. You can read about it at:
http://en.wikipedia.org/wiki/Perfect_number
or at a number of other sites as well.
Your next move after that should be to do some computation by hand and see why 6 and 28 are perfect numbers and others in between are not.
At that point you will hopefully be ready to make use of the hint I have given you in #218267.
Hi Roger, Do you think i'm anywhere close to that?
disp('Perfect numbers!');
disp('Enter two numbers(intervals)');
num1 = input('Enter num1 value: ');
num2 = input('Enter num2 value: ');
fprintf('Perfect numbers between %d and %d are: ', num1, num2);
for N = num1:num2-1;
S = sum(N(mod(n,N)==0));
fprintf('%d, ',s)
end
end

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

태그

질문:

2015년 5월 27일

댓글:

2015년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by