syntax for loop output implementation

I need help to implement this for loop program as shown below with ten different outputs
f = 25 ;
for m = 0:10:80;
Zcb = 104.5;
l = 3.75e-3 ;
Zo = (1 + (0.055*(1-1i))/sqrt(f));
n = 800 ;
x = 1;
P = 800;
Z1 = 1+((m)*sin(2*pi*n*x/P));
ZB = abs(Zcb*Zo*Z1);
u = ((494)+(36/f))*1.0e-9;
Vpk = 100/u ;
Attk = (1.80*sqrt(f)+ 0.005*(f)+ 0.25/sqrt(f));
Qk = ((Attk)*(0.01))/(8.68588963807);
Bk = (2*pi*f*1.0e6)/(Vpk);
Yk =(Qk + 1i*Bk);
H = (1.0000 + 0.0000i);
N = (0.0000 + 0.0029i);
Ds = (2*ZB.*Zo*H) + ((ZB.^2+Zo^2)*N);
SB11 = ((ZB.^2-Zo^2)*N)/Ds;
SB12 = (2*ZB.*Zo)/Ds;
SB21 = (2*ZB.*Zo)/Ds;
SB22 = ((ZB.^2-Zo^2)*N)/Ds;
% Program to convert S matrix to T matrix
TB11 = ((SB12*SB21)-(SB11*SB22))/SB21;
TB12 = (SB11/SB21);
TB21 = -(SB22/SB21);
TB22 = (1/SB21);
TB = [TB11 TB12;TB21 TB22];
end
% program to get the sequential product of TB from the for loop above
T = TB1*TB2*TB3*TB4*TB5*TB6*TB7*TB8*TB9*TB10;

 채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 15일

0 개 추천

Don't do that. Use one of the alternatives.
Or, unless you have a particular need to store all of the intermediate matrices, start with
T = eye(2);
and then in each iteration of the loop,
T = T * TB;
then at the end, T will hold the result you are looking for.

댓글 수: 5

Segun  Emmy
Segun Emmy 2013년 9월 15일
Sir should do it this way? T = eye(2); T = T*TB; T = prod(T);
No. prod() is element-by-element multiplication. T*TB is doing matrix multiplication. Write it out
(((eye * first_TB) * second_TB) * third_TB) * fourth_TB
is the same as
eye * first_TB * second_TB * third_TB * fourth_TB
which is the same as
first_TB * second_TB * third_TB * fourth_TB
Segun  Emmy
Segun Emmy 2013년 9월 15일
Sir I mean what syntax can I use to call or say reference the matrix outputs TB (without need to begin to display and write them out) and then use them in serial multiplication i.e. TB*TB*TB*TB*TB*TB*TB*TB*TB*TB where TB are *different output 2 by 2 matrix from the for loop iteration. Thanks
Walter Roberson
Walter Roberson 2013년 9월 15일
편집: Walter Roberson 2013년 9월 15일
Unless you need to use the individual matrices for something other than the serial multiplication, do not store all of the individual matrices: you only need them for a brief moment.
f = 25 ;
T = eye(2);
for m = 0:10:80;
Zcb = 104.5;
l = 3.75e-3 ;
Zo = (1 + (0.055*(1-1i))/sqrt(f));
n = 800 ;
x = 1;
P = 800;
Z1 = 1+((m)*sin(2*pi*n*x/P));
ZB = abs(Zcb*Zo*Z1);
u = ((494)+(36/f))*1.0e-9;
Vpk = 100/u ;
Attk = (1.80*sqrt(f)+ 0.005*(f)+ 0.25/sqrt(f));
Qk = ((Attk)*(0.01))/(8.68588963807);
Bk = (2*pi*f*1.0e6)/(Vpk);
Yk =(Qk + 1i*Bk);
H = (1.0000 + 0.0000i);
N = (0.0000 + 0.0029i);
Ds = (2*ZB.*Zo*H) + ((ZB.^2+Zo^2)*N);
SB11 = ((ZB.^2-Zo^2)*N)/Ds;
SB12 = (2*ZB.*Zo)/Ds;
SB21 = (2*ZB.*Zo)/Ds;
SB22 = ((ZB.^2-Zo^2)*N)/Ds;
% Program to convert S matrix to T matrix
TB11 = ((SB12*SB21)-(SB11*SB22))/SB21;
TB12 = (SB11/SB21);
TB21 = -(SB22/SB21);
TB22 = (1/SB21);
TB = [TB11 TB12;TB21 TB22];
T = T * TB;
end
disp('Result of multiplication of all the matrices together is'), T
Segun  Emmy
Segun Emmy 2013년 9월 15일
Thanks sir it worked perfectly when I tried it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 9월 15일

0 개 추천

I don't really totally understand this alphabet soup of code, but TB is complex, and in the line
T = TB1*TB2*TB3*TB4*TB5*TB6*TB7*TB8*TB9*TB10;
you don't have 10 variables TB1 through TB10, so I don't know what you intend there.

댓글 수: 2

Segun  Emmy
Segun Emmy 2013년 9월 15일
편집: Segun Emmy 2013년 9월 15일
Sir the ten variables will come from the output of the for loop. If you look at the question you see for m = 0:10:80; The TB is been computed for this range m = 0:10:80.My problem is how to make the computer display TB as TB1,TB2...TB10 so that I can use it for multiplication. Thanks as I await your help.
Image Analyst
Image Analyst 2013년 9월 15일
Is TB supposed to be a complex (imaginary) number? Because it is.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by