Hi, thank you for using health care magic.
As you describe you can maintain erection while alone means nothing wrong with physical.
Many times there are isolated incident of loss of erection , if so just forget that you have anything wrong and keep confidence while sexual activity.
If loss of erection occurs regularly then there should be a psychological problem for not maintaining erection while intercourse.
Psychological causes are multiple few of them which are very common are poor first intercourse experience , low confidence , lack of proper arousal , thinking about performance (performance
anxiety), Poor intimacy, rapid and
premature ejaculation , lack of isolated environment for sexual activity etc.
Try to find out those causes and if you are unable to find take help of
psychiatrist. With proper environment and focusing on intimacy during intercourse, erection should improve .
Hope you find this helpful.
Regards.