In recent years, machine learning methods have been used to solve partial differential equations (PDEs) and dynamical systems, leading to the development of a new research field called scientific machine learning, which combines techniques such as deep neural networks and statistical learning with classical problems in applied mathematics. In this paper, we present a novel numerical algorithm that uses machine learning and artificial intelligence to solve PDEs. Based on the Legendre-Galerkin framework, we propose an unsupervised machine learning algorithm that learns multiple instances of the solutions for different types of PDEs. Our approach addresses the limitations of both data-driven and physics-based methods. We apply the proposed neural network to general 1D and 2D PDEs with various boundary conditions, as well as convection-dominated singularly perturbed PDEs that exhibit strong boundary layer behavior.