Federated scientific machine learning for approximating functions and solving differential equations with data heterogeneity