Let's say money is no problem - this is a young enthusiast from a rich family, not someone who needs to be able to earn a living. A young person that has passion for science - chemistry, engineering, physics or any other science will do. Willing to move wherever needed to learn.
What would be the best schools for that? My admittedly hazy perception is that the bulk of universities focused on a classical education at the time.
I apologize in advance; my specialty is history of mathematics, so the answer will be very mathematician-centric. But all statements apply to all other STEM disciplines. I also apologize that I'm going to move away from 1840 by a few decades in either direction because it's hard to find anyone from that exact time period, but really the circumstances about the 18th and 19th centuries are more or less the same. Since you asked about „persons“ I will say a little bit about both men and women. As a final caveat, I would like to point out that I will be talking primarily about the situation in Europe. This is for the following reasons: The scientific research community in America was just emerging at that time, so those who were really interested in science often went to Germany or France to study (Parshall & Rowe 1994), for example Grace Chisholm and Henry Young, who met in Göttingen and later did mathematical research together after they went back to the U.S. (Mühlhausen 2020).
I have no deep knowledge of the Asian region, but I know that some women went to the U.S. to study medicine including Kei Okami from the Japanese Empire (Presbyterian Church 1889), Anandi Gopal Joshi from India (Joshi 1992), and Sabat M. Islambouli from Persia (Farhan 2022). The reason for this was that the U.S. was one of the few countries where women could attend university at that time. And thus, quite a few came, like Henriette Hirschfeld, later the first female dentist in Germany. Her later sister in law Franziska Tiburtius went to Switzerland, were at least foreign women (and later Swiss women too, at least in theory) were allowed to study. (Tiburtius 1929).
But what is really true at any point in time is obviously also true in the middle of the 19th century: money opens all doors. Another option for women from famillies with the necessary means were private tutors. Ada Lovelace, daughter of the famous poet Lord Byron, received private lessons from Charles Babagge (and later worked with him on the difference engine, a concept for a computer that was of course only theoretical at the time, but on whichthe first computers developed at Harvard during World War II were later based)(Hollings, Martin & Rice 2017). A little later, Sofya Kovalevskaya, a Russian from the lower gentry, also received private lessons when her mathematical talent was recognized (Koblitz 1993). The mathematician Gustav Bauer, a student of the (at least in my circles) famous Lejeune Dirichlet taught as a private tutor in the house of Prince Ghica from1845 onwards (Faber 1953).While there werequite a few you men from rich families who were tutored privately, for them going to university was the standard way to recieve aneducation if they were interested in the sciences.
Actually, it can be stated that, with a few exceptions, such as Gauss, who came from a humble backgroundand received a royal scholarship at the end of the 18th century due to hisoutstanding talent (Dunnington, Gray & Dohse 2004), all students at universities were at least from the middle class. On the one hand, attending university cost money, and on topof that, the young men often had to move out of their homes, thus incurring additional living costs. On the other hand, only in the financially stableclasses was it possible for sons to be taught long enough, either by privatetutors or by attending school, for the requirements for university attendance to be met. Even though I only list examples below, they are very representativeof the average student body at the time.Henri Poincaré studied at the École des Mines, and his father was a professor (Gray 2013). The father of Wilhelm and Alexander von Humboldt was chamberlain to the Princess of Prussia (and Alexander's godfather even was the Prussian Crown Prince Friedrich Wilhelm II) - both studied in Frankfurt an der Oder after being taught by a private tutor in their youth (Biermann 1990). Charles Darwin was the son of a doctor and studied inEdinburgh from 1830 onward (Browne 2003). While private tutoring was the norm for royal offspring, even they sometimes attended the university (although of course there was no need for them to graduate): Prince Albert of Saxe-Coburg and Gotha studied at the University of Bonn from 1837-1838 (Bosbach 2010).
In summary, the following rule of thumb can be stated: For both girls and boys from a wealthy background, private education was a very common option. If women wanted to study afterwards, they had to go to a country that allowed women to study. Men, if they did were not educated privately their entire life like most from the gentry, could go to all universities, and those who really wanted a good education went to France or Germany.
Sources
Biermann, K.-H. (1990). Alexander von Humboldt. 4.Auflage. Teubner.
Bosbach, F. (Ed.). (2010). Die Studien des Prinzen Albertan der Universität Bonn (1837-1838) (Vol. 5). Walter de Gruyter.
Browne, E. J. (2003). Charles Darwin: The power of place(Vol. 2). Princeton University Press.
Faber, G. (1953). Bauer,Gustav. In: Neue Deutsche Biographie (NDB). Band 1,Duncker & Humblot.
Dunnington, G. W., Gray, J., & Dohse, F. E. (2004). Carlfriedrich gauss: Titan of science. MAA.
Farhan, S. (2022). Women Doctors and the Medical Professionin Iraq during the First Half of the Twentieth Century. Journal of MiddleEast Women's Studies, 18(1), 59-80.
Gray, J. (2013). Henri Poincaré: A scientific biography.Princeton University Press.
Hollings, C., Martin, U., & Rice, A. (2017). The earlymathematical education of Ada Lovelace. BSHM Bulletin: Journal of the British Society for the History of Mathematics, 32(3), 221-234.
Joshi, S. J. (1992). Anandi Gopal. Bhatkal & Son.
Koblitz, A. (1993). A convergence of lives. AConvergence of Lives. Rutgers University Press.
Mühlhausen, E. (2020). Grace Chisholm Young, William Henry Young, Their Results on the Theory of Sets of Points at the Beginning of theTwentieth Century, and a Controversy with Max Dehn. In Against All Odds(pp. 121-132). Springer, Cham.
Parshall, K. H., & Rowe, D. E. (1994). The emergenceof the American mathematical research community, 1876-1900: JJ Sylvester, Felix Klein, and EH Moore (Vol. 8). American Mathematical Soc..
Presbyterian Church (1889). "Women'sForeign Missionary Society of the Presbyterian Church". Woman's Work forWoman and Our Mission Field. Women's Foreign Missionary Societies of the Presbyterian Church. IV: 136, 333.
Tiburtius, F. (1929). Erinnerungen einer Achtzigjährigen(Vol. 1). Schwetschke.