Matlab Code:
clear all
clc
j=sqrt(-1);
prompt= 'enter the value of power factor, if PF is lagging enter
the value in negitive : ';
requiredpf=input(prompt)
v=200; f=60;
z1=100; z2=10+20i;
z=1/((1/z1)+(1/z2));
S=conj((v^2)/z);
P=real(S);
theta1=angle(S);
theta2= acos(requiredpf);
C= (P*(tan(theta1)-(tan(theta2))))/(2*pi*f*v^2)
disp('values after capacitor placed in parallel :')
xc=1/(2*pi*60*C*j)
Znew= 1/((1/z1)+(1/z2)+(1/xc));
Itotal= v/Znew
Snew= conj(v^2/Znew);
Ptotal= real(Snew)
Rtotal=imag(Snew)
sample Matlab example for one of the power
factor:
enter the value of power factor, if PF is lagging enter the
value in negitive : -0.8
requiredpf =
  -0.8000
C =
  1.6579e-04
values after capacitor placed in parallel :
xc =
  0.0000 -16.0000i
Itotal =
  6.0000 + 4.5000i
Ptotal =
       1200
Rtotal =
-900.0000
>>
%%if you are having any doubts please comment here or
else rate me%%