About a third of men over 40 have erectile problems. The worst offenders are anti high blood pressure and diuretic medicines. A unifying factor is lack of oxygen to the penis causing poor formation of the chemical messenger nitric oxide. Often there is more than one cause, some vessel narrowing, some lowering of testosterone, and some lack of local chemical messengers. A good medical history includes an assessment of sexual function.
Diagnostic tests can tell a lot.
Some men are impotent because of depression which can be miraculously cured by appropriate medicines. Ability to have an erection in dream time can be checked by a ring of stamps or plumber's tape circling the penis or a more sophisticated strain gauge. Blood pressure in the penis can be measured by Doppler techniques before and after exercise. Sex hormones can be checked by blood tests. If you can climb a flight of stairs, you can have intercourse but having the woman on top will reduce exertion.