bitxor of two numbers
조회 수: 1 (최근 30일)
이전 댓글 표시
I am using the following code to generate random sequence. But error message' Double inputs must have integer values in the range of ASSUMEDTYPE.' is coming. PLS HELP.
function [xout,yout, x0, y0] = ginger(x0,y0)
% Gingerbreadman map producing a chaotic 2-D map.
% if not enough inputs, assign random numbers
if nargin < 2
x0 = randn();
y0 = randn();
end
% iteration counter
n = 20000;
x = zeros(n,1);
y = zeros(n,1);
% main calculation
% Taking different values of r from 0.2 to 3.8. we can take
%cos also insted of sine.
for i = 1:n
if i == 1
x(i) = 1 - y0 + abs(x0);
y(i) = x0+3.8*cos(y0);
else
x(i) = 1 - y(i-1) + abs(x(i-1));
y(i) = x(i-1)+3.8*cos(y(i-1));
end
end
% if output is requested, return gingerbread x,y values and
% x0, y0 initial conditions
% otherwise plot results
if nargout > 0
xout = x;
yout = y;
else
scatter(x, y, '.');
c=bitxor(x,y);
end
댓글 수: 1
Walter Roberson
2019년 12월 5일
c is not an output and is not used later on. Why are you calculating it?
답변 (2개)
Walter Roberson
2019년 12월 5일
c = typecast( bitxor(typecast(x, 'uint64'), typecast(y, 'uint64')), 'double');
Expect to see a lot of values in the range 1e-308, and be aware that creating a double out of arbitrary bit streams can leave you with values that are denormalized or are one of the many many different kinds of nan or "signaling nan". You can create values that, if MATLAB were to take you seriously, would result in MATLAB creating an error message about invalid operations (signalling nans), except MATLAB will not take you seriously. Also note that MATLAB treats all nans the same for most purposes, so once you have managed to create these nans, you will have a hard time telling them apart.
All in all, doing a bitxor between two doubles is a Bad Idea.
댓글 수: 2
Walter Roberson
2019년 12월 5일
Should the pseudo-random sequence be integer or floating point? What range should it have? What distribution should it have (ideally) ?
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!