If a husband is physically incapable or performing onah (the obligation for a husband to sexually satisfy his wife as outlined in Shulchan Aruch Even Ha'Ezer 76)due to an inability to have an erection is that husband obligated to purchase medicine or have a surgery which will remove his inability?
The Mahari'k in shoresh 10' says that the chiuv onah is considered davar she'bemomon meaing a monetary issue.Therefore a person must give all he has got to fulfill it.
We see that when paying a debt the bais din takes away all but a few things.Which tells us that more than a chomesh which is required for an Assay is required of someone looking to pay his debts.Therefore that which shall be an excuse in a regular mitvah shall not be sufficient in a monetary issue.
According to this certainly the husband is obligated to treat his condition.However even according to the shulchan aruch that it not considered monetary which is why he can not make a condition with a wife to be exempt of this obligation according to the shulchan aruch,nevertheless since it is interpersonal it will require him to do his utmost to fulfill it and act on it as though it were monetary.
In conclusion he is obligated to heal himself of this shortcoming for his wife's sake.
In regard to whether or not the husband may rely on the forgiving of his wife and not treat his deficiency,or is it a chesed on the wife's part to be forgiving in this area.
The Gemarah in Yevomot 109'b' relay's an episode where Chonyov the son of Shimon Ha'Tsaddik was offered the Kehunah Gedolah after the passing of his father. He declined as respect to his older brother, letting him take it for himself. After a while jealousy took hold of him, which led him to disgrace his brother thereby causing himself to have to run for his life to Egypt and build what became known as Bais Chonyov to serve as his Bais Hamikdash.
The depth in this story is as,cited in that Gemarah,Rav Yehohuah Ben Peracyah said "before i became Nassi i would say that if someone were to push me to accept such a position i shall give him over to the lions,and now after being Nassi if someone should tell me to step off i would spill burning hot water on him".
This meaning, that when giving up an opportunity so tempting as this,one shall be sure that his heart is fully compliant with it.For when the jealousy kicks in later it shall be it shall be in great measures,and will leave you in a state of inconsolable regret.
Now,in our case,do we know that the wife is all forgiving and not suffering in silence? Is she really complacent being robbed of her basic rights?
Therefore i conclude that the husband should not rely on his wife's forgiveness and should undoubtfully treat the condition and give her that which she deserves.
From the simple reading of the Shulchan Aruch E"H 76.11 it seems
That medical problems are an excuse, not to fullfill a man's marital obligation, but it works only up to 6 months,
After 6 months the wife has the right to demand a divorce (and since it is his fault (even if not directly since only the woman has the claim of your field got inundated) he is obligated to give the whole kesuba), or forgive her husbands obligation.
(The commentators (on that sif) say:)
But if the doctors claim it will get better in a specific time even after 6 months then she will have to wait until it happens
So it seems in your case you can not take the medication/operation up to 6 months.
after that if you did not take them your wife can demand a divorce
PS That was the law but it seems to be good behavior to heal yourself asap, since peace in your house is a big mitzvah , and your organ is called the peace maker in your house (shabos 152a)
the Lubavicher Rebbe who would be the last person to tell someone to give up , advised at least 3 times for men to give in to their wife's demands (with dignity (becouse they are not woman (weak minded, easaly offended) so it is they who are the ones to give in)) Igros 1141 , 1154 and 2454
PPS it is possible that I the wife forgives the husband obligation towerds her she is also fulling the mitzvah of making peace between a husband and wife
I guess this halacha in the Rambam (Avodim End) can be applied here by both parties
And whoever shows mercy to others will have mercy shown to him, as implied by Deuteronomy 13:18: "He will show you mercy, and be merciful upon you and multiply you."