Last active
July 18, 2023 15:01
-
-
Save Ebrahim-Ramadan/4a37027e3a520c717bf2ce6bdd9d976b to your computer and use it in GitHub Desktop.
The Transfer Matrix Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % This code is to perform the transfer matrix method | |
| % T{1},T{2},T{3}, have been already calculated. they are | |
| % obviously 2 by-2 matrices. Now we want to obtain vector D{i} for each transfer matrix coefficients above. | |
| T{1} = [0.9982 - 0.0616i, -0.0119 + 0.0121i; | |
| -0.0119 - 0.0121i, 0.9982 + 0.0616i]; | |
| T{2} = [0.9831 - 0.1845i, -0.0157 - 0.0149i; | |
| -0.0157 + 0.0149i, 0.9831 + 0.1845i]; | |
| T{3} = [0.9527 - 0.3040i, -0.0074 + 0.0080i; | |
| -0.0074 - 0.0080i, 0.9527 + 0.3040i]; | |
| %Multiply T matrices | |
| M{1} = T{1}; | |
| M{2} = T{1} * T{2}; | |
| M{3} = T{1} * T{2} * T{3}; | |
| D = cell(1, 4); % Initialize cell array to store D{i} | |
| for i = 1:3 | |
| d1(i) = 1; | |
| d2(i) = M{i}(2, 1) / M{i}(1, 1); % r; | |
| d1(i+1) = 1 / M{i}(1, 1); % t; | |
| d2(i+1) = 0; | |
| D{i+1} = [d1(i+1); d2(i+1)]; | |
| end | |
| D{4} = zeros(2, 1); % Initialize D{4} as zero vector | |
| for i = 3:-1:1 | |
| D{i} = M{i} * D{i+1}; | |
| end | |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| % Check if D{1} is equal to TMC{1} * D{2} | |
| is_equal1 = isequal(D{1}, M{1} * D{2}); | |
| disp(is_equal1); | |
| % Check if D{2} is equal to TMC{2} * D{3} | |
| is_equal2 = isequal(D{2}, M{2} * D{3}); | |
| disp(is_equal2); | |
| % Check if D{3} is equal to TMC{3} * D{4} | |
| is_equal3 = isequal(D{3}, M{3} * D{4}); | |
| disp(is_equal3); | |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment