%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % csum.m - forms the sum of a series of complex numbers % and displays the result in both polar and % rectangular format. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% S=0; disp(' '); disp(' SUM OF COMPLEX NUMBERS'); disp(' '); disp(' Form: 1-polar, 2-rectangular'); disp(' '); nterms=input('How many numbers to be added? '); disp(' '); for i=1:nterms; F=input(['Form of ',num2str(i),' = ']); if (F~=1 & F~=2); disp('INVALID FORM'); end if F==1 M=input(['Mag ',num2str(i),' = ']); A=input(['Deg ',num2str(i),' = '])*pi/180; S=S+M*exp(j*A); disp(' '); else R=input(['Real ',num2str(i),' = ']); I=input(['Imag ',num2str(i),' = ']); S=S+R+j*I; disp(' '); end end disp(' '); disp(['SUM = ' num2str(real(S)) ' +j '... num2str(imag(S)) ' = ' num2str(abs(S)) '|_'... num2str(angle(S)*180/pi) 'deg']);