The purpose of this paper is to study numerically the influence of the magnetic field, buoyancy force and viscous dissipation on the convective flow and temperature of the fluid in a square cavity, lid-driven cavity, and lid-driven cavity with an obstacle at the center. The continuity, momentum and energy equations are coupled including buoyancy and magnetic forces, and energy equation contains Joule heating and viscous dissipation. The equations are solved in terms of stream function, vorticity and temperature by using polynomial radial basis function (RBF) approximation for the inhomogeneity and particular solution. The numerical solutions are obtained for several values of Grashof number (Gr), Hartmann number (M) for fixed Prandtl number Pr = 0:71 and fixed Reynolds number Re = 100 with or without viscous dissipation. It is observed that in the absence of obstacle, viscous dissipation changes the symmetry of the isotherms, and the dominance of buoyancy force increases with an increase in Gr, whereas decreases when the intensity of magnetic field increases. The obstacle in the lid-driven cavity causes a secondary flow on its left part. The effect of moving lid is weakened on the flow and isotherms especially for large Gr when the cavity contains obstacle.