Reputation: 9
I am making a Mersenne Generator in MATLAB and I am using the code as follows:
%// Define parameters
a=65539;
c=0;
x0=1;
m=2^31;
%// Calculate sequence using recursion relation
xn=zeros(20000,1);
for i=1:20000
xn(i)=mod(a*x0+c,m);
x0=xn(i);
end
%// Divide by m to give real numbers between 0 and 1
un=xn/m;
%// Plot 3-tuples of the u_i in 3D space
plot3(un(1:end-2),un(2:end-1),un(3:end),’b.’);
xlabel(’u_i’); ylabel(’u_{i+1}’); zlabel(’u_{i+2}’); grid(’on’);
When I run it in my MATLAB, it gives me the following error:
plot3(un(1:end-2),un(2:end-1),un(3:end),’b.’);
Error: The input character is not valid in MATLAB statements or expressions.
Any help would be appreciated.
Upvotes: 0
Views: 510
Reputation: 104504
The single quotations at the end of the plot
code are unicode versions that MATLAB does not accept. This is probably because you copied and pasted the code from Microsoft Word or some other text editor that transformed single quotations into those screwed up characters instead.
Actually use single quotation characters:
plot3(un(1:end-2),un(2:end-1),un(3:end),'b.');
%// ^ ^
xlabel('u_i'); ylabel('u_{i+1}'); zlabel('u_{i+2}'); grid('on');
%// ^ ^ ^ ^ ^ ^ ^ ^
Upvotes: 4