code

Download code

If you can't read please download the document

Upload: shivam-garg

Post on 05-Nov-2015

212 views

Category:

Documents


0 download

DESCRIPTION

this code is of CAD algo

TRANSCRIPT

function []=mainmain()format;load -mat rc_line.dat;%LINELEM= [86 0 1 0 2 3 5.0e-10 2.0e+00 2.0e-9 2 2.5e-9 0; 82 100 1 2 0 0 0 0 0 0 0 0 ; 67 5.0e-13 2 0 NaN 0 0 0 0 0 0 0 ];%NODES=[101 102];% to check if file is loaded the following command is given%disp(LINELEM);global BetaP;%BetaP=0.5*MU*COX*30e-6*0.35e-6;global deltaT;deltaT= 1e-10;%1.0e-9;global simTime;simTime= 0;%1.0e-5;global timeStep;timeStep=deltaT;global NODES1;NODES1=NODES;%NODES=[103 105 ];[LIN_mat_rowNumber,LIN_mat_cols]=size(LINELEM); % number of linear elemts%[NLN_mat_rowNumber, Cols]=size(NLNELEM);%[NLN_mat_size,LIN_mat_cols]=size(NLNELEM); %number of non linear elementsglobal MNA_size;MNA_size = numel(NODES1);% calculating number of nodesdisp(MNA_size);global numberOfNodes;numberOfNodes= numel(NODES);global DC_NV; DC_NV=zeros(numberOfNodes,1);global Y_Mat; % creation of zero matrix for storing stamp valuesY_Mat = zeros(MNA_size);global v_Mat ; %creation of v matrixv_Mat = zeros (MNA_size, 1);global J_Mat; % creation of J matrixJ_Mat= zeros(MNA_size,1);global branchCurrent; % to store branch currentsbranchCurrent=zeros(MNA_size,1);global storeCurrent; % Index used to stamp voltage, needed to get last index usedstoreCurrent=0;global storeCurrentIndex;storeCurrentIndex=1;%capIndexStore = 1;%% Stamp Volatge Last index usedglobal New_MNA_size;New_MNA_size= MNA_size;global localVolt; % to be used for storing instant voltages in stampCap()localVolt=0;global localCur; % to be used for storing instant curent in stampCap()localCur=0;global timeElapsed; % to be used for storing instant curent in stampCap()timeElapsed=0;global capCount; % to be used for storing instant count of caps to find current for localCurcapCount=0;global b;global iterationC; % to be used for iteration count such that new iterations coud be done w/o creating new memoryiterationC=0;global iterationL; % for inductoriterationL=0;global capIndexStoreIndex;capIndexStoreIndex=1;global localVolti;localVolti=0;global caps;% this will store all the capacitor valuesglobal loopInt3;loopInt3=1;global final_out;final_out=1;global variable;variable=0;global nodeVoltage;nodeVoltage=0;global t;% used in trans function to set voltagest=0;global RUN; RUN=0;notToBeUsedVaribale4=1;%do_DC(LINELEM,NLNELEM, LIN_mat_rowNumber);% for running rc_mesh this is%commenteddo_DC(LINELEM, LIN_mat_rowNumber);% solves the dc operating point of system b=linsolve(Y_Mat, J_Mat); for j=1:numberOfNodes DC_NV(j,1)=b(j,1); % This is for storing DC_Node volatges. DC_Node Currents can be stored in similar way if required end % DC Branch Currents% for j=1:numberOfNodes% branchCurrent(j,1)=;% end %disp(b); disp('DC Y_Mat'); disp(Y_Mat); disp('DC_NV:');disp(DC_NV); disp('DC J_Mat=');disp(J_Mat); % END OF DC__END OF DC__END OF DC__END OF DC__END OF DC__END OF DC__END OF DC__END OF DC__while (timeElapsed= LINELEM(i,7+2*t)) t=t+1; if(t==(LINELEM(i,6))) t=t-1; end end if((time+deltaT)< LINELEM(i,7+2*t) ) if(t==0) SLOPE= LINELEM(i,8)/LINELEM(i,7); stampVol((deltaT+time)*SLOPE, LINELEM(i,3), LINELEM(i,4)); else SLOPE= (LINELEM(i,8+2*t)-LINELEM(i,8+2*(t-1)))/ (LINELEM(i,7+2*t)-LINELEM(i,7+2*(t-1))); stampVol((((deltaT+time-LINELEM(i,7+2*(t-1)))*SLOPE)+ LINELEM(i,8+2*(t-1))), LINELEM(i,3), LINELEM(i,4)); end end end elseif ((LINELEM(i,1)== 67)) %CAPACITOR__CAPACITOR__CAPACITOR__CAPACITOR__CAPACITOR__CAPACITOR__CAPACITOR__ if(RUN==0) if (iterationC==0) if(LINELEM(i,4)0) J_Mat(J_Mat_rowValue, 1) = currentValue; J_Mat(J_Mat_colValue, 1) = -1* currentValue;% J_Mat(J_Mat_rowValue, 1) = J_Mat(J_Mat_rowValue, 1) + currentValue; % J_Mat(J_Mat_colValue, 1) = J_Mat(J_Mat_colValue, 1) - currentValue;elseif(J_Mat_rowValue>0 && J_Mat_colValue