Toghril Beg, the founder of the Seljuk dynasty, had made Esfahan the capital of his domains and his grandson, Malik-Shah Jalal al-Din, had ruled there since 1073. An invitation was sent to Khayyam from Malik-Shah and from his vizier, Nizam al-Mulk, asking Khayyam to go to Esfahan to set up an observatory there. Other leading astronomers were also brought to the observatory in Esfahan, and for 18 years Khayyam led the scientists and produced work of outstanding quality. It was a period of peace during which the political situation allowed Khayyam the opportunity to devote himself entirely to his scholarly work.
During this time Khayyam led work on compiling astronomical tables and he also contributed to calendar reform in 1079. It was to be his greatest achievement. Developed in response to the Seljuk sultan's need for a new schedule for revenue collection, Khayyam's calendar, called Al-Tarikh-al-Jalali after the sultan, was even more accurate than the Gregorian calendar presently used in most of the world: the Jalali calendar had an error of one day in 3770 years, while the Gregorian has an error of one day in 3330 years. Khayyam measured the length of one year as 365.24219858156 days, which is remarkably accurate. It has since been discovered that the number changes in the 6th decimal place over a person's lifetime. For comparison of Khayyam's accuracy, the length of one year at the end of the 19th century was 365.242196 days, and today it is 365.242190. Although the calendar project was canceled upon Malik-Shah's death in 1092, the Jalali calendar has survived and is still used in parts of Iran and Afghanistan today.
The death of the sultan, a month after his vizier Nizam al-Mulk was murdered on the road from Esfahan to Baghdad by the terrorist movement called the Assassins, ended Khayyam's period of peaceful existence. Malik-Shah's second wife took over as ruler for two years but she had argued with Nizam al-Mulk, so support was withdrawn from his clients and funding for the Observatory ceased and Khayyam's calendar reform was put on hold. Khayyam also came under attack from the orthodox Muslims who felt that Khayyam's questioning mind did not conform to the faith.
Despite being out of favor on all sides, Khayyam remained at the Court. He wrote a work in which he described former rulers in Iran as men of great honor who had supported public works, science and scholarship.
http://www.islamonline.net/english/scie ... le04.shtml