\(Đặt:n_{Al}=a\left(mol\right);n_{Mg}=b\left(mol\right)\left(a,b>0\right)\\ PTHH:2Al+3H_2SO_4\rightarrow Al_2\left(SO_4\right)_3+3H_2\\ Mg+H_2SO_4\rightarrow MgSO_4+H_2\\ \Rightarrow\left\{{}\begin{matrix}27a+24b=4,5\\1,5.22,4a+22,4b=5,04\end{matrix}\right.\Leftrightarrow\left\{{}\begin{matrix}a=0,1\\b=0,075\end{matrix}\right.\\ \Rightarrow\%m_{Al}=\dfrac{0,1.27}{4,5}.100=60\%\\ \Rightarrow\%m_{Mg}=100\%-60\%=40\%\)