Hi, my name is***** for writing to us. Sorry you are suffering with this problem. If you can masturbate with ease but cannot maintain a erection when another person is involved, it is possible you are suffering from "performance anxiety" or a psychological barrier to your erection. The first thing you should do is make an appointment to see your doctor to rule out any physical health causes. If there aren't any physical reasons for inability to sustain an erection (and there may not be since you can achieve erection and orgasm through masturbation), then it is likely they will recommend you talk to a mental health professional to dig out some of the other reasons this is happening to you. Be assured that performance anxiety is common so if this is psychological, with the right support such as through a therapist, you can overcome this.
Hope this helps,