bitxor of two numbers
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 5 Dez. 2019
c is not an output and is not used later on. Why are you calculating it?
Antworten (2)
Walter Roberson
am 5 Dez. 2019
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 Kommentare
Walter Roberson
am 5 Dez. 2019
Should the pseudo-random sequence be integer or floating point? What range should it have? What distribution should it have (ideally) ?
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!