Skip to content

Commit

Permalink
Getting the "proper" equation coefficients, see #80
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 16, 2025
1 parent 618fee1 commit dc366f2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
4 changes: 2 additions & 2 deletions js/bloch-sphere/model/StateDirection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import quantumMeasurement from '../../quantumMeasurement.js';
import { MeasurementAxis } from './MeasurementAxis.js';

export class StateDirection extends EnumerationValue {
public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' );
public static readonly Z_MINUS = new StateDirection( '-Z', Math.PI, 0, 'ZMinus' );
public static readonly X_PLUS = new StateDirection( '+X', Math.PI / 2, 0, 'XPlus' );
public static readonly X_MINUS = new StateDirection( '-X', Math.PI / 2, Math.PI, 'XMinus' );
public static readonly Y_PLUS = new StateDirection( '+Y', Math.PI / 2, Math.PI / 2, 'YPlus' );
public static readonly Y_MINUS = new StateDirection( '-Y', Math.PI / 2, 3 * Math.PI / 2, 'YMinus' );
public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' );
public static readonly Z_MINUS = new StateDirection( '-Z', Math.PI, 0, 'ZMinus' );
public static readonly CUSTOM = new StateDirection( 'Custom', 0, 0, 'Custom' );

public static readonly enumeration = new Enumeration( StateDirection );
Expand Down
36 changes: 31 additions & 5 deletions js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,40 @@ export default class BlochSphereNumericalEquationNode extends HBox {
blochSphere.azimuthalAngleProperty,
options.basisProperty
],
( polarAngle, azimuthalAngle, basisProperty ) => {
( polarAngle, azimuthalAngle, basis ) => {

let upCoefficientValue;
let downCoefficientValue;
let azimuthalCoefficientValue;

const projectionToCoefficient = ( value: number ) => {
return Math.sqrt( ( value + 1 ) / 2 );
};

switch( basis ) {
case StateDirection.X_PLUS:
upCoefficientValue = projectionToCoefficient( Math.cos( azimuthalAngle ) * Math.sin( polarAngle ) );
downCoefficientValue = projectionToCoefficient( -Math.cos( azimuthalAngle ) * Math.sin( polarAngle ) );
azimuthalCoefficientValue = 0;
break;
case StateDirection.Y_PLUS:
upCoefficientValue = projectionToCoefficient( Math.sin( azimuthalAngle ) * Math.sin( polarAngle ) );
downCoefficientValue = projectionToCoefficient( -Math.sin( azimuthalAngle ) * Math.sin( polarAngle ) );
azimuthalCoefficientValue = 0;
break;
default: // StateDirection.Z_PLUS
upCoefficientValue = Math.abs( Math.cos( polarAngle / 2 ) );
downCoefficientValue = Math.abs( Math.sin( polarAngle / 2 ) );
azimuthalCoefficientValue = azimuthalAngle / Math.PI;
break;
}

// Update the coefficients of the state equation.
const upCoefficientString = Utils.toFixed( Math.cos( polarAngle / 2 ), 2 );
const downCoefficientString = Utils.toFixed( Math.sin( polarAngle / 2 ), 2 );
const azimuthalCoefficientString = Utils.toFixed( azimuthalAngle / Math.PI, 2 );
const upCoefficientString = Utils.toFixed( upCoefficientValue, 2 );
const downCoefficientString = Utils.toFixed( downCoefficientValue, 2 );
const azimuthalCoefficientString = Utils.toFixed( azimuthalCoefficientValue, 2 );

const direction = basisProperty.description.split( '' )[ 1 ];
const direction = basis.description.split( '' )[ 1 ];

return `|${PSI}⟩ = ${upCoefficientString} |${UP}<sub>${direction}</sub> ${KET} + ` +
`${downCoefficientString}e<sup>i${azimuthalCoefficientString}${PI}</sup> |${DOWN}<sub>${direction}</sub> ${KET}`;
Expand Down

0 comments on commit dc366f2

Please sign in to comment.