Cody

Solution 1831626

Submitted on 30 May 2019 by William
  • Size: 90
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
user_solution = fileread('spin_matrices.m'); assert(isempty(strfind(user_solution,'regexp'))); assert(isempty(strfind(user_solution,'num2str'))); assert(isempty(strfind(user_solution,'interp'))); assert(isempty(strfind(user_solution,'fprintf'))); assert(isempty(strfind(user_solution,'assert')));

2   Pass
% use auxiliary functions iseq = @(x,y)norm(x-y)<=64*eps; % check if equal up to 64 eps com = @(x,y)x*y-y*x; % commutator trace= @(x) sum(diag(x)); % trace % fprintf('Testing...\n') for s = 1/2:1/2:5, % Get the matrices fprintf('\ts=%-3s : ',strtrim(rats(s))); [Sx,Sy,Sz] = spin_matrices(s); % % ancillary parameters mz = (-s:s)'; % eigenvalues S2 = Sx^2+Sy^2+Sz^2; % S^2 matrix % assert(trace(Sx)==0&&iseq(Sx,Sx'),'Sx must be a traceless Hermitian matrix'); assert(trace(Sy)==0&&iseq(Sy,Sy'),'Sy must be a traceless Hermitian matrix'); assert(trace(Sz)==0&&iseq(Sz,Sz'),'Sz must be a traceless Hermitian matrix'); % % actual values assert(iseq(com(Sx,Sy),1i*Sz), 'Commutation relations: [Sx,Sy] = i*Sz') assert(iseq(com(Sy,Sz),1i*Sx), 'Commutation relations: [Sy,Sz] = i*Sx') assert(iseq(com(Sz,Sx),1i*Sy), 'Commutation relations: [Sz,Sx] = i*Sy') % assert(iseq(S2,s*(s+1)*eye(2*s+1)), 'S^2 must be a quantum number!'); assert(iseq(eig(Sz),mz), 'Sz must be a quantum number!'); % fprintf('OK!\n'); end % fprintf('\n \nWolfgang Pauli would be proud!\n') %

Testing... s=1/2 : OK! s=1 : OK! s=3/2 : OK! s=2 : OK! s=5/2 : OK! s=3 : OK! s=7/2 : OK! s=4 : OK! s=9/2 : OK! s=5 : OK! Wolfgang Pauli would be proud!

Suggested Problems

More from this Author18