Looping problem in this program
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Venkatkumar M
le 28 Juin 2019
Rouvert : Venkatkumar M
le 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 commentaires
Geoff Hayes
le 28 Juin 2019
Venkatkumar - please clarify what you mean by The Ampersand symbol (&), from start to end, has to be put into a loop. Also, where is n defined? Is that the iterating variable in your for loop? Can you show all of your code?
Réponse acceptée
Image Analyst
le 28 Juin 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 commentaires
Image Analyst
le 28 Juin 2019
Try:
for n = 2 : length(VLi)
VLi(n)=VRr(n-1);
VRi(n)=VLr(n+1);
end
As for "Every n of VLin =VRin is equal to zero (how to define it)" I don't have the slightest idea what that means. Perhaps get someone else to look over the wording to help you epxlain it better.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!