help in matlab

Thread Starter

NOW

Joined Dec 21, 2012
6
i have a problem here
in making a project for some transmition line i made code in matlab which is down and the matlabe dos not run it ,why??????:cool::(
f=0:10e9/201:10e9;
for t=1:202
f0=5e9;
Z0=50;
w=pi*f(t)/(2*f0);
a=cos(w);
b=j*Z0*sin(w);
c=j*sin(w)/Z0;
d=cos(w);
a1=cos(w);
b1=j*Z0*sin(w)/sqrt(2);
c1=j*sqrt(2)*sin(w)/Z0;
d1=cos(w);
x0=[1 0 0 0 0 0 a1 c1]';
x1=[0 -1 0 0 0 0 0 0]';
x2=[(a*Z0)+b (c*Z0)+d -Z0 0 0 0 0 0]';
x3=[-a*Z0 -c*Z0 Z0 -1 0 0 0 0]';
x4=[0 0 (a1*Z0)+b1 (c1*Z0)+d1 -Z0 0 0 0]';
x5=[0 0 0 0 -a*Z0 (Z0*c)+1 -Z0 0]';
x6=[0 0 a1*Z0 Z0 b-Z0 d 0 0]';
x7=[0 0 0 0 0 0 0 1]';
x8=[0 0 0 0 a*Z0 -c*Z0 Z0-b1 -d]';
y=[x1 x2 x3 x4 x5 x6 x7 x8];
y1=[x0 x2 x3 x4 x5 x6 x7 x8];
y2=[x1 x0 x3 x4 x5 x6 x7 x8];
y3=[x1 x2 x0 x4 x5 x6 x7 x8];
y4=[x1 x2 x3 x0 x5 x6 x7 x8];
y5=[x1 x2 x3 x4 x0 x6 x7 x8];
y6=[x1 x2 x3 x4 x5 x0 x7 x8];
y7=[x1 x2 x3 x4 x5 x6 x0 x8];
y8=[x1 x2 x3 x4 x5 x6 x7 x0];
ia1=det(y1)/det(y);
ia2=det(y2)/det(y);
ib1=det(y3)/det(y);
ib2=det(y4)/det(y);
ic1=det(y5)/det(y);
ic2=det(y6)/det(y);
id1=det(y7)/det(y);
id2=det(y8)/det(y);
i1=ia1+id1;
i2=ia2+ib1;
i3=ib2+ic2;
i4=id2-ic1;
Zin=1/i1;


G=(Zin-Z0)/(Zin+Z0);

Gin=sqrt(real(G)^2+imag(G)^2);
p1=(1-Gin^2)/(2*Z0);
p2=i2^2*Z0;
p3=i3^2*Z0;
p4=i4^2*Z0;

GdB=10*log(Gin);
end

plot(f,GdB);
 

panic mode

Joined Oct 10, 2011
4,975
you are going through loop to calculate something for many points, but result is stored in ONE point only. try to replace third last line to

GdB(t)=10*log(Gin);

if you are to plot something, it has to be a vector or array
 

panic mode

Joined Oct 10, 2011
4,975
if you have an error, you need to check what line of code causes it. matlab gives quite detailed feedback. i just run this and it worked for me:

Rich (BB code):
f=0:10e9/201:10e9;

f0=5e9; // there is no point to place this inside the loop 
Z0=50;
    
for t=1:202
    w=pi*f(t)/(2*f0);
    a=cos(w);
    b=j*Z0*sin(w);
    c=j*sin(w)/Z0;
    d=cos(w);
    a1=cos(w);
    b1=j*Z0*sin(w)/sqrt(2);
    c1=j*sqrt(2)*sin(w)/Z0;
    d1=cos(w);
    x0=[1 0 0 0 0 0 a1 c1]';
    x1=[0 -1 0 0 0 0 0 0]';
    x2=[(a*Z0)+b (c*Z0)+d -Z0 0 0 0 0 0]';
    x3=[-a*Z0 -c*Z0 Z0 -1 0 0 0 0]';
    x4=[0 0 (a1*Z0)+b1 (c1*Z0)+d1 -Z0 0 0 0]';
    x5=[0 0 0 0 -a*Z0 (Z0*c)+1 -Z0 0]';
    x6=[0 0 a1*Z0 Z0 b-Z0 d 0 0]';
    x7=[0 0 0 0 0 0 0 1]';
    x8=[0 0 0 0 a*Z0 -c*Z0 Z0-b1 -d]';
    y=[x1 x2 x3 x4 x5 x6 x7 x8];
    y1=[x0 x2 x3 x4 x5 x6 x7 x8];
    y2=[x1 x0 x3 x4 x5 x6 x7 x8];
    y3=[x1 x2 x0 x4 x5 x6 x7 x8];
    y4=[x1 x2 x3 x0 x5 x6 x7 x8];
    y5=[x1 x2 x3 x4 x0 x6 x7 x8];
    y6=[x1 x2 x3 x4 x5 x0 x7 x8];
    y7=[x1 x2 x3 x4 x5 x6 x0 x8];
    y8=[x1 x2 x3 x4 x5 x6 x7 x0];
    ia1=det(y1)/det(y);
    ia2=det(y2)/det(y);
    ib1=det(y3)/det(y);
    ib2=det(y4)/det(y);
    ic1=det(y5)/det(y);
    ic2=det(y6)/det(y);
    id1=det(y7)/det(y);
    id2=det(y8)/det(y);
    i1=ia1+id1;
    i2=ia2+ib1;
    i3=ib2+ic2;
    i4=id2-ic1;
    Zin=1/i1;


    G=(Zin-Z0)/(Zin+Z0);

    Gin=sqrt(real(G)^2+imag(G)^2);
    p1=(1-Gin^2)/(2*Z0);
    p2=i2^2*Z0;
    p3=i3^2*Z0;
    p4=i4^2*Z0;

    GdB(t)=10*log(Gin); // this is the only true change (made GdB an array)
end

plot(f,GdB);
 

Attachments

panic mode

Joined Oct 10, 2011
4,975
also put this as first line of any matlab script:

Rich (BB code):
clc; clear all; close all;
so every time you run some code, you get clean sheet. you can use break points to stop code at particular places and narrow down what causes issues, check variables etc.
 

Thread Starter

NOW

Joined Dec 21, 2012
6
if you have an error, you need to check what line of code causes it. matlab gives quite detailed feedback. i just run this and it worked for me:

Rich (BB code):
f=0:10e9/201:10e9;

f0=5e9; // there is no point to place this inside the loop 
Z0=50;
    
for t=1:202
    w=pi*f(t)/(2*f0);
    a=cos(w);
    b=j*Z0*sin(w);
    c=j*sin(w)/Z0;
    d=cos(w);
    a1=cos(w);
    b1=j*Z0*sin(w)/sqrt(2);
    c1=j*sqrt(2)*sin(w)/Z0;
    d1=cos(w);
    x0=[1 0 0 0 0 0 a1 c1]';
    x1=[0 -1 0 0 0 0 0 0]';
    x2=[(a*Z0)+b (c*Z0)+d -Z0 0 0 0 0 0]';
    x3=[-a*Z0 -c*Z0 Z0 -1 0 0 0 0]';
    x4=[0 0 (a1*Z0)+b1 (c1*Z0)+d1 -Z0 0 0 0]';
    x5=[0 0 0 0 -a*Z0 (Z0*c)+1 -Z0 0]';
    x6=[0 0 a1*Z0 Z0 b-Z0 d 0 0]';
    x7=[0 0 0 0 0 0 0 1]';
    x8=[0 0 0 0 a*Z0 -c*Z0 Z0-b1 -d]';
    y=[x1 x2 x3 x4 x5 x6 x7 x8];
    y1=[x0 x2 x3 x4 x5 x6 x7 x8];
    y2=[x1 x0 x3 x4 x5 x6 x7 x8];
    y3=[x1 x2 x0 x4 x5 x6 x7 x8];
    y4=[x1 x2 x3 x0 x5 x6 x7 x8];
    y5=[x1 x2 x3 x4 x0 x6 x7 x8];
    y6=[x1 x2 x3 x4 x5 x0 x7 x8];
    y7=[x1 x2 x3 x4 x5 x6 x0 x8];
    y8=[x1 x2 x3 x4 x5 x6 x7 x0];
    ia1=det(y1)/det(y);
    ia2=det(y2)/det(y);
    ib1=det(y3)/det(y);
    ib2=det(y4)/det(y);
    ic1=det(y5)/det(y);
    ic2=det(y6)/det(y);
    id1=det(y7)/det(y);
    id2=det(y8)/det(y);
    i1=ia1+id1;
    i2=ia2+ib1;
    i3=ib2+ic2;
    i4=id2-ic1;
    Zin=1/i1;


    G=(Zin-Z0)/(Zin+Z0);

    Gin=sqrt(real(G)^2+imag(G)^2);
    p1=(1-Gin^2)/(2*Z0);
    p2=i2^2*Z0;
    p3=i3^2*Z0;
    p4=i4^2*Z0;

    GdB(t)=10*log(Gin); // this is the only true change (made GdB an array)
end

plot(f,GdB);
but in the command windows gives me an error....!!
 

panic mode

Joined Oct 10, 2011
4,975
Rich (BB code):
clc; clear all; close all;

f=0:10e9/201:10e9;
f0=5e9;
Z0=50;
    
for t=1:202
    w=pi*f(t)/(2*f0);
    a=cos(w);
    b=j*Z0*sin(w);
    c=j*sin(w)/Z0;
    d=cos(w);
    a1=cos(w);
    b1=j*Z0*sin(w)/sqrt(2);
    c1=j*sqrt(2)*sin(w)/Z0;
    d1=cos(w);
    x0=[1 0 0 0 0 0 a1 c1]';
    x1=[0 -1 0 0 0 0 0 0]';
    x2=[(a*Z0)+b (c*Z0)+d -Z0 0 0 0 0 0]';
    x3=[-a*Z0 -c*Z0 Z0 -1 0 0 0 0]';
    x4=[0 0 (a1*Z0)+b1 (c1*Z0)+d1 -Z0 0 0 0]';
    x5=[0 0 0 0 -a*Z0 (Z0*c)+1 -Z0 0]';
    x6=[0 0 a1*Z0 Z0 b-Z0 d 0 0]';
    x7=[0 0 0 0 0 0 0 1]';
    x8=[0 0 0 0 a*Z0 -c*Z0 Z0-b1 -d]';
    y=[x1 x2 x3 x4 x5 x6 x7 x8];
    y1=[x0 x2 x3 x4 x5 x6 x7 x8];
    y2=[x1 x0 x3 x4 x5 x6 x7 x8];
    y3=[x1 x2 x0 x4 x5 x6 x7 x8];
    y4=[x1 x2 x3 x0 x5 x6 x7 x8];
    y5=[x1 x2 x3 x4 x0 x6 x7 x8];
    y6=[x1 x2 x3 x4 x5 x0 x7 x8];
    y7=[x1 x2 x3 x4 x5 x6 x0 x8];
    y8=[x1 x2 x3 x4 x5 x6 x7 x0];
    ia1=det(y1)/det(y);
    ia2=det(y2)/det(y);
    ib1=det(y3)/det(y);
    ib2=det(y4)/det(y);
    ic1=det(y5)/det(y);
    ic2=det(y6)/det(y);
    id1=det(y7)/det(y);
    id2=det(y8)/det(y);
    i1=ia1+id1;
    i2=ia2+ib1;
    i3=ib2+ic2;
    i4=id2-ic1;
    Zin=1/i1;


    G=(Zin-Z0)/(Zin+Z0);

    Gin=sqrt(real(G)^2+imag(G)^2);
    p1=(1-Gin^2)/(2*Z0);
    p2=i2^2*Z0;
    p3=i3^2*Z0;
    p4=i4^2*Z0;

    GdB(t)=10*log(Gin);
end

plot(f,GdB);
 

panic mode

Joined Oct 10, 2011
4,975
i don't know what are you talking about. i just run the code and posted screenshot. and i just repeated it using code in post #10. can you at least tell where you get the warning? what line of code? how are you testing it? are you typing the code in the command window or executing it as a script?

just open matlab, go to menu File, New, Script and paste code from post #10. then press F5 to run it. if prompted save it anywhere and choose "Change Folder". that's it.
 

Thread Starter

NOW

Joined Dec 21, 2012
6
this what i have:

> In YESm at 33
Warning: Divide by zero.
> In YESm at 34
Warning: Divide by zero.
> In YESm at 35
Warning: Divide by zero.
> In YESm at 36
Warning: Divide by zero.
> In YESm at 37
Warning: Divide by zero.
> In YESm at 38
Warning: Divide by zero.
> In YESm at 39
Warning: Divide by zero.
> In YESm at 40
Warning: Imaginary parts of complex X and/or Y arguments ignored.
> In YESm at 61
Warning: Divide by zero.
> In YESm at 33
Warning: Divide by zero.
> In YESm at 34
Warning: Divide by zero.
> In YESm at 35
Warning: Divide by zero.
> In YESm at 36
Warning: Divide by zero.
> In YESm at 37
Warning: Divide by zero.
> In YESm at 38
Warning: Divide by zero.
> In YESm at 39
Warning: Divide by zero.
> In YESm at 40
Warning: Imaginary parts of complex X and/or Y arguments ignored.
> In YESm at 61
>>
 
Top