Saturday, February 20, 2010

Finding My Matlab Plp How Can I Make This Program Work? It's In Matlab,to Find The First 7 Perfect Numbers With Efficient Code?

How can i make this program work? It's in Matlab,to find the first 7 perfect numbers with efficient code? - finding my matlab plp

This is my program so far:

currentNumber = 6;

counter = 0;

while (count \\ \\ \\ \\ \\ \\ \\ \\ u0026lt 4)

for i = 2: sqrt (current number);

if MOD (currentNumber i) ~ = 0;% consider factors currentNumber

Mp = (2. Current Number ^) - 1;% estimated Mersenne prime
End
End

counter = counter + 1;
disp (sprintf ( 'A Mersenne prime is:% d', Mp))
perfectn = 0.5 * (Mp + 1) * MP
End

Current Number currentNumber + = 1;
% Checks for the next perfect number
End

does not work and I do not understand why. Firstly, wrote a program to find the first four perfect numbers, that works, but it is naiveSearch from any divisor of the number and inserts it much longer.

Please help!

1 comments:

wiseguy said...

Dear Spell case

When you debug a program, it is useful to check the actual values of the variables against the values that we hold. If you find something unexpected, you may be wondering, "What are the causes? You can then follow the chain of calculations, you return the item if the cause was actually a previous calculation instead of the place when you notice that something does not seem to mind do. Of course, with a summary of the program is no problem with line by line, all of this, and make sure each step is doing what you want. We'll see what the program actually does (you can tell if it is what we want it). Remember, however, the program will do exactly whatsay to do it, not what you want to do.

The first reason can not, the program works, is the last line of code. You have complete unmatched (ie four ANS, but only three can be used together with time, FP, and MI).

Well, according to the program of the series, we see what follows.

- The current number is variable at 6 and disadvantages of value 0.

- From the Counter u0026lt \\ \\ \\ \\ \\ \\ \\ \\, 4, in the loop.

- It is stipulated that the 2 is on top of the loop and the loop are executed only once, since the latter condition,
sqrt (6), re-raise by a second loop.

- In the loop if mod (currentNumber i) is not zero. Since mod (6.2) equal to zero, we calculate mp.Program control goes to the end of the IF-block, then at the end of the loop. The loop ends at this point, as described above.

- Now the counter is incremented by 1.

- The DISP statement has a problem, because Mp is undefined (recall that the line with the clock in the IF block is not executed, so that Mp never been assigned a value).

- The calculation has the same problem perfectn Mp is undefined (Matlab, if not stopped, if he is found, the statement DISP obliged to him), unstoppable.

- Due to an error is detected, the program will not continue, because it prevents the execution currentNumber ALL go and do not change with a value of 6.


If you have further questions, pleaselater updated code, or send an e-mail. It would be useful to more comments on exactly what he expects from each line to see how he helps others understand your intentions and actual behavior of the code.

Post a Comment