Looping problem in this program

4 views (last 30 days)
Venkatkumar M
Venkatkumar M on 28 Jun 2019
Reopened: Venkatkumar M on 21 Jan 2022
Vs=1;
rs=1;
rl=1;
r=10;
ll=2e-3;
VRi(n)=0;
VLi(n)=0;
l=5e-3;
c=10e-6;
g=1;
zo=sqrt(l/c);
t=sqrt(l*c);
zl=(2*ll)/t;
%VOLTAGE AND CURRENT
%n=1
V1=((Vs/rs)+((2*VRi1))/(r+zo))/((1/rs)+(1/(r+zo)));
i1=((V1-(2*VRi1))/(r+zo));
VR1=(2*VRi1)+(i1*zo);
%n=2,....,n-1 (i.e n=2)
&
V2=(((2*VLi2/(zo))+((2*VRi2)/(zo+r)))/((1/zo)+(1/(r+zo)+(g)))); % Every n of VLi n =VRi n is equal to zero (how to define it)
i2=((V2-(2*VRi2)/(r+zo)));
VL2=V2;
VR2=(2*VRi2)+(i2*zo);
&
%n=n(i.e n=11)
V11=(((2*VL11/(zo))+(2*Vi/(rl+zl)))/((1/zo)+(1/(zl+rl)+(g))));
IL=((V11-(2*Vi))/(rl+zl));
V=(2*Vi)+(il*zl);
%REFLECTED VOLTAGES
%n=1
VRr1=VR1-VRi1;
%n=2,....,n-1 (i.e n=2)
&
VLr2=VL2-VLi2;
VRr2=VR2-VRi2;
&
%n=n(i.e n=11)
VLr11=V11-VLi11;
%INCIDENT VOLTAGES
%n=1
VRi1=VLr2;
%n=2,3,....,n-1 (i.e n=2)
&
VLi2=VRr1;
VRi2=VLr3;
&
%n=n(i.e n=11)
VLi11=VRr10;
Vi=-Vr;
The Ampersand symbol (&), from start to end, has to be put into a loop. How do I do it?
  2 Comments
Venkatkumar M
Venkatkumar M on 28 Jun 2019
Given code is full code
VLi(n)=VRr(n-1);
VRi(n)=VLr(n+1);
i just need this section (and the section with &)to be looped for n=2,3,...,n-1

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 28 Jun 2019
Put
for k = 1 : numIterations
before the code that you want to be in the loop, and
end
after the code. numIterations is how many times you want to do the loop. Please look at
and this link also:
I have no idea what the ampersands are supposed to do so it's difficult to advise you further. For example, maybe
VRi1=VLr2;
%n=2,3,....,n-1 (i.e n=2)
&
VLi2=VRr1;
VRi2=VLr3;
&
%n=n(i.e n=11)
VLi11=VRr10;
means
result = VRi1 == VLr2 && ...
VLi2 == VRr1 && ...
VRi2 == VLr3 && ...
VLi11 == VRr10;
but I really have no idea what your intent is.
And for testing equality of floating point numbers, See the FAQ
  3 Comments
Venkatkumar M
Venkatkumar M on 30 Jun 2019
Capture3.PNG
Compare img with the first program
now do u able get it?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by