A study of processes that vary with time can be conducted using time-varying dynamical systems. This work presents the solution representation of the time-varying \(\psi \) -Caputo and \(\psi \) -Hilfer multi-order dynamical system and a scientific machine learning algorithm to simulate \(\psi \) -Caputo-type equations with a detailed error analysis. The solution representation for the time-varying \(\psi \) -Caputo and \(\psi \) -Hilfer type dynamical system uses state transition matrices. The multi-layer perceptron and the Kolmogorov–Arnold network architecture are used to propose the scientific machine learning algorithm. Further, the Kumar–Ertuk method is extended to the \(\psi \) -Caputo sense to reduce the discretization error of the \(\psi \) -Caputo derivative. A detailed error analysis of the algorithm is presented. Further, the algorithm is implemented on toy problems, such as the epidemiological model and problem with the exact solution, and the accuracy of both approaches is compared by using the exact solution. The proposed method is also compared with several methods in the literature, such as the predictor-corrector, L1-based predictor–corrector, Haar wavelet method, and the physics-informed neural network with L1-based discretization to highlight the effect of the proposed method. From the comparison, it was concluded that the proposed method reduces the error by order 1 and is 10 to 100 times more accurate than other methods. Also, the proposed approach is applied to forecast the price of Netflix stock and prices of indices such as Nasdaq, Dow Jones, S &P 500, Nifty 50, BSE, and Nikkei.