필터 지우기
필터 지우기

Different values obtained from same function file on different computers

조회 수: 3 (최근 30일)
ahmad eldeeb
ahmad eldeeb 2018년 8월 23일
편집: Stephen23 2018년 8월 24일
Hello, I use particle swarm built-in function on matlab 2017b. I have my function file that to optimized. I got results. I took this results to another computer with the same version of matlab and resubtitute in the same function file with the optimum position but I don't get the same value of function. The two computers are 64 bit. Any solution, or what is the right answer.
  댓글 수: 11
ahmad eldeeb
ahmad eldeeb 2018년 8월 24일
I tried or the commented lines. Some give the same results but with the same warning.
Stephen23
Stephen23 2018년 8월 24일
편집: Stephen23 2018년 8월 24일
@ahmad eldeeb: I was not talking about inv, I was talking about your original question: i.e. why the same function on two different machines produces two different values with the same input data. You have made it clear that there are no random numbers, so your best option is to do some debugging, exactly as I described in my last comment. This has nothing (in particular) to do with inv or any warnings, it is solely a method to find out where the data in the two functions diverge from each other. At this point debugging and comparing the intermediate calculations is what I would do, and what other experienced users would do. You can too!
Probably the first and most important step is to confirm that the two functions are actually the same: the MATLAB IDE has a file comparison tool to help with that:

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

답변 (1개)

Steven Lord
Steven Lord 2018년 8월 23일
There are many reasons why calling the same function file twice with the same inputs may return different answers. The most common is, as Adam Danz said, calling the random number generators.
function y = myfun415924(x)
y = x + randi([0 10], 1);
Now call this function repeatedly:
z = zeros(1, 10);
for k = 1:10
z(k) = myfun415924(5);
end
disp(z)
You may have some duplicate values in z, but you will also have some values that are different. If you want reproducible results in this type of scenario, control the random number generator to generate random numbers that are repeatable. [Note: you may be tempted later on to adapt my example to change the random number generator state at each iteration of a loop to generate "more random" numbers. DON'T. As that documentation page states, reseeding too frequently may be hazardous to the statistical properties of your random numbers.]
z = zeros(1, 10);
for k = 1:10
rng default
z(k) = myfun415924(5);
end
disp(z)
  댓글 수: 7
ahmad eldeeb
ahmad eldeeb 2018년 8월 23일
i don'y use rand or particleswarm in the function fuile.
Adam Danz
Adam Danz 2018년 8월 23일
Hi Ahmad, I just glanced at your code briefly and saw 3 built-in functions in the first few lines:
size(); round(); sum()
A built-in function is a function that comes along with Matlab. Many of Matlab's built-in function use randomization. I suggest you take the advice of Jan and Stephen and it also wouldn't hurt to try the random number seed that I suggested above to rule out any random processes that you may be unaware of.

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

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by