- The result of (j*w0*C) has the size of 7x6 matrix
- But G is a 7x7 matrix
- So you are getting dimension mismatch error
Help needed to calculate complex voltage
    5 views (last 30 days)
  
       Show older comments
    
I'm trying to calculate the complex voltage and a magnitude plot for a circuit with my code. However I am not generating the plot as expected (plot should look like a bode plot) and am not sure what I am doing wrong. Below is the code I have as well as the code for the function I am using in my main code.
   %%Main code
   rs   =  4000
   r1   =  8000
   r2   =  4000 
   re   =  3300
   rc   =  6000 
   rl   =  4000 
   r0   =  103500
   rpi  =  2610 
   c1   = 1*10^(-6)
   c2   = 1*10^(-6)
   ce   = 10*10^(-6)
   cpi  = 17*10^(-12)
   cmew = 2.5*10^(-12)
   gm   = 38.5*10^(-3)
   Vg   = 1 
   G = [(1/rs),(-1/rs), 0, 0, 0, 0, 1;...
       (-1/rs), (1/rs), 0, 0, 0, 0, 0;... 
       0, 0, ((1/r1)+(1/r2)+(1/rpi)), (-1/rpi) 0, 0, 0;...
       0, 0, ((-1/rpi)-gm), ((1/rpi)+(1/r0)+gm+(1/re)),((-1/r0)), 0, 0;...
       0, 0, gm,((-1/r0)-gm), ((1/r0)+(1/rc)), 0, 0;... 
       0, 0, 0, 0, 0,(1/rl), 0;... 
       1, 0, 0, 0, 0, 0, 0] 
   C = [0, 0, 0, 0, 0, 0, 0;...
       0, c1, -c1, 0, 0, 0, 0;...
       0, -c1, (c1+cmew+cpi), -cpi, -cmew, 0, 0;...
       0, 0, -cpi, (ce+cpi), 0, 0, 0;...
       0, 0, -cmew, 0, (c2+cmew), -c2, 0;...
       0, 0, 0, 0, -c2, c2, 0;...
       0, 0, 0, 0, 0, 0, 0]
   w = [0;0;0;0;0;0;Vg] 
    a = [1 2 3 4 5 6 7 8 9];
    z = [a 10*a 100*a 1000*a 10000*a 100000*a 1000000];
    [magnitude,phase] = bode1(G,C,w,z)
  end
%%Function for [magnitude,phase] = bode1(G,C,w,z)%%
 function [mag,phase] = bode1(G,C,w,z)
  for n = 1:length(z) 
      w0 = z(n)*2*pi;
        A = G+(j*w0*C);
        x = w'*inv(A);
        t = abs(x);
        i =(180/pi)*angle(x);
        if n == 1
            magnitude = t;
            phas = i;
        else
            magnitude = [magnitude t];
            phas = [phas i];
        end
        [m1, n1] = size(magnitude);
        [m2, n2] = size(phas);
        mag(1:m1,1:n1,n) = magnitude(:,:); 
        phase(1:m2,1:n2,n) = phas(:,:); 
    end   
end
0 Comments
Answers (1)
  Stalin Samuel
      
 on 27 Feb 2017
        0 Comments
See Also
Categories
				Find more on Optics in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
