Illegal use of reserved keyword

9 views (last 30 days)
vs=10;
r=1;
c=1;
dt=0.1;
z=dt/(2*c);
i= vs/r;
vi=-(i*z)/2;
for j=0:0.1:1
{
if j = 0
{
vr[j]=0-vi;
}
else
{
vr[j+1]=vr[j];
}
end
ik[j]=(vs-(2*vr[j]))/(r+z);
it[j]=(vs/r)*(exp(-j/(r*c)));
vc[j]=(2*vr[j])+(ik[j]*z);
vcr[j]=vc[j]-vr[j]
}

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 10 Jun 2019
Edited: Bjorn Gustavsson on 10 Jun 2019
The curly brackets are used to enclose cell-arrays (lists) in matlab, not start and end loops and if-clauses, matlab uses nothing to start those and end to close them. So:
for i1 = 1:4,
if x > 0
a(i1) = pi^i1;
else
a = -23;
end
end
also, I would suggest staying away from i and j for indexing, since they are the imaginary unit too, sooner or later it might come and bite you at an inopportune moment, I go with i1, i2, or i_t, i_x...
HTH
  14 Comments
Venkatkumar M
Venkatkumar M on 14 Jun 2019
my code is on modeling of transmission line.
Thank you very much

Sign in to comment.

More Answers (1)

Matt J
Matt J on 10 Jun 2019
You have written your code with C-language syntax. Matlab and C are not the same language.
  2 Comments
Matt J
Matt J on 10 Jun 2019
It should be something pretty easy for you to do yourself, assuming you've been through Matlab's Getting Started documentation.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by