My Quantum Journey #02: Qubit Probability Amplitude Calculator in MATLAB

August 13, 2026 • 0 comments

Original image, made in GIMP, of ket notation psi, as a depiction of calculating the qubit probability amplitude in quantum computing, made possible by KrisComputes!

Let's remind ourselves the qubit probability amplitude:

$$\ket{\psi} = \begin{bmatrix} \alpha \\ \beta \end{bmatrix} = \alpha\ket{0} + \beta\ket{1}$$

For \(\alpha\) and \(\beta\), they are the absolute value of complex numbers—squared:

$$|\alpha|^2 + |\beta|^2$$

Here's my first iteration of the qubit probability amplitude, this time, in MATLAB:

                                      

alpha = sqrt(3)/2;
beta = 1/2;

coeffSq1 = abs((alpha)^2);
coeffSq2 = abs((beta)^2);
summed = coeffSq1 + coeffSq2;

normalized = 1.0;

if  abs(summed - normalized) < 1e-12
    disp('System is normalized!');
else
    disp('System is not normalized.');
end

                                      
                                    

Having used MATLAB during the time I went back to school, majoring in math, made me fascinated with the language. However, like my time in video production, where there's been countless of this tribe-like mentality, with fans defending what brand(s)—languages—they like, alongside slandering those who prefer something else, MATLAB gets plenty of hate for some odd reason (Java, included). Having dabbled with this language for a while, both on and off classes, I realize how much I love it, alongside R; and as someone who, then, earned that BA in Mathematics, languages like MATLAB makes sense to me. Given that MathWorks announced plug-ins and tools for quantum computing was enough to have me jump into it! After composing this program, much like my GitHub repository I made for my research paper Milk Crate Challenge: Statistical Findings Behind the Social Media Phenomenon in MATLAB, I'm reminded how awesome and clean writing code for this is.

Oh, but the expansion has just begun: like I did writing this in R, I added a 'while' loop to take user input and simply do the calculations:

                                       

qubitLoop = true;

while qubitLoop

    entered1 = 'Enter the first coefficient: ';
    alpha = input(entered1);
    disp([num2str(alpha), ' it is!']);
    entered2 = 'Now enter the second coefficient: ';
    beta = input(entered2);
    disp([num2str(beta), '. Great!']);

    fprintf("Adding both coefficients--alpha and beta--gives us:\n\n");
    coeffSq1 = abs((alpha)^2);
    coeffSq2 = abs((beta)^2);
    disp(['Alpha: ', num2str(coeffSq1)]);
    disp(['Beta: ', num2str(coeffSq2)]);
    fprintf("\n");
    fprintf("Adding them both gives us: \n");
    summed = coeffSq1 + coeffSq2;
    disp([num2str(summed)]);

    normalized = 1.0;

    if  abs(summed - normalized) < 1e-12
        fprintf("System is normalized!\n");
    else
        fprintf("System is not normalized.\n");
    end

    answer = input('Would you like to calculate another pair of qubit amplitudes? (y/n) ', 's');

    if strcmpi(answer,'y')
        qubitLoop = true;
    else
        fprintf("Thanks for using this program! Closing...\n")
        qubitLoop = false;
    end

end

                                      
                                    

Honestly, you can imagine the fun I'd have using MATLAB for my class assignments that time (I still kept all my homework assignments I did, just to look back and practice on my own). In case I haven't mentioned it previously, I believe I was the only one to say that I wanted to become proficient in this language in front of both my classmates and professors! I have no shame: if I like it, I really like it.

However, for my code, I took extra time in wanting to know the cleanest way in writing this. Using the "disp([])" function is alright, until I could do this:

                                        
    fprintf('Alpha: %g\n', coeffSq1);
    fprintf('Beta: %g\n', coeffSq2);
                                        
                                    

MATLAB: The Path Least Taken

Some of you have guessed that I'm gradually recovering from burnout. July was the month my ailments started to show, given that I've put in so much hours crafting, writing, and analyzing my own programming projects. I was immediately turned off by the fact that it was programming—software engineering—that was the culprit of this. Having done programming, on and off, since 2009, the landscape changed, and it's hyper competitive out there; let alone the levels of stress and mental instability, in addition. I think it's built for those who either grew up with that kind of adrenaline or those who are used to it and love the challenge(s). Maybe because I'm about to approach the age of 40, but given that I've played sports at a young age, I'm not as agile as I once was. I don't feel old, but parts of me are. Programming is a young man's discipline, and while I enjoyed the process, which led me to loving and majoring, plus self-studying, mathematics, writing code is something only youngsters are cut out for (much respect for those my age or older who can write and craft code in an instant). There'll always be joy in writing code, but unfortunately, it has made me dreary, realizing that such changing landscape works best for those able to absorb plenty in a short amount of time.

However, all is not lost. I realized that the nature of programming languages, because there are so many, was another reason for being overwhelmed with choices; as if I needed to choose something specific in order to stand out. Not to be: whether it gets me hate or not, I find MATLAB to be one of the most, if not, the most, logical and cleanest language I've written in. It writes like a math statement, making the language so straight-forward to write in. Since then, I don't see myself writing in any other language than MATLAB and R; to add another would bring me back into that overwhelmed state that nearly affected my health because of burnout (my diet has long been affected, and have been working on that currently). Overall, writing in MATLAB is such a rewarding experience, and I won't change that for the world; gives me more reasons why I love math, and proud to have majored in it.

I'm truly aware that reports marked MATLAB declining in popularity. I'm not sure if it'll go in the way of COBOL or Pascal, especially given the costs to use it, in spite of being able to write AND compile MATLAB code in the terminal, perhaps there aren't as much computational mathematicians/researchers using it; I believe they're using Python, C++, and Julia to name a few. Whatever the case, use what you plan on using, and be good at it; in addition to preventing being overwhelmed, stick to one or two languages (unless you're able to handle more, then great). Burnout is no joke, and it's becoming a quiet, almost unreported, epidemic currently. I wouldn't wish it on anyone nor anything because it's that bad (I don't know how YouTubers are able to deal and manage such stress, especially those who post videos every day). All in all, feel no shame for what you decide to write programs in because there are plenty of obstacles to tackle. You don't need extra stresses from others maliciously attacking you for using a programming language they dislike, then blaming you for not succumbing to their disdain(s). Go out and get the job done, and do it in a diligent way without wearing yourself thin (in other words, don't do what I did, having fell for that "hustle culture" as it's not worth it in the long run).

I'm Kris Caballero, and this is what I computed today.


Comments

Add Comment

* Required information
1000
Drag & drop images (max 3)
Enter the word table backwards.
Captcha Image

Comments

No comments yet. Be the first!
⇈