I learned I can calculate the entropy $$S=-k_B\sum_jp_j\ln(p_j)$$ where
$p_j$ is the probability at state $j$.
but I saw that the entropy is also can be calculated by
$$S=-k_B\ln(Z)$$ I think this equation applicable for both of isolated
system and non isolated system
these two equations are same ?
Given the number of states $\Omega(E,\Delta E)$ within $\Delta E$ of the thermodynamic energy $E$, the entropy is:
$$
S=k\ln(\Omega)\;.
$$
If the quantity $Z$ is defined such that
$$
\Omega =\frac{1}{Z(E)}\;,
$$
I.e., if $Z(E)$ is the statistical distribution function, i.e. $Z(E_n)$ is your probability $p_n$, then
$$
S=-k\ln(Z)
$$
But, we know that the log of the statistical distribution function is a linear function of the constants of motion (actually just $E$, ignoring total momentum and total angular momentum as usual)
$$
\ln Z(E)=a + bE\;,
$$
so that the averaging that was performed to obtain the average energy $E$
$$
E=\sum_n Z(E_n)E_n
$$
can be "pulled outside" the log
$$
\ln Z(E)=\sum_n p_n\ln(p_n)\;,
$$
where we have written $p_n=Z(E_n)$.
Thus, so too,
$$
S=-k\sum_n p_n\ln(p_n)
$$