John W. Hinckley Jr. believes his attack on President Reagan accomplished its intended purpose, linking him "forever in history" with actress Jodie Foster and changing her life so that "she can never go anywhere without thinking of him," a defense psychiatrist testified yesterday.

"He indicated to me that he wanted and he felt that he had indeed impressed her and that they were linked forever in history, that they would be forever, and that he had altered her life forever, no matter what else happened," Dr. Thomas C. Goldman told the jury.

Goldman, the third defense psychiatrist to testify, has had 17 interviews with Hinckley since the March 30, 1981, attack on Reagan, including three interviews in the courthouse cellblock since the trial began more than three weeks ago. His most recent interview was a three-hour session 11 days ago.

He told the jury that Hinckley believes if Foster ignores him now, she is "trying to deny a relationship that exists." Hinckley thinks that when Foster rejects him, it is due to "some personal ill-feeling toward him," Goldman said.

"What he cannot countenance is that fact, which I think is plainly observable to everyone, anyone here, that he does not have a relationship with her, that he does not matter to her," he added.

Hinckley became angry with his defense lawyers when they refused to take messages from him to Foster after his arrest, Goldman said, and he staged a hunger strike in prison because he was unable to contact her.

Two weeks ago, when Foster said flatly in a videotaped deposition that she had no relationship with Hinckley, Hinckley stormed out of his trial. In the videotape played for the jury, there was no mention of what effect the whole situation has had on Foster.

During yesterday's court session, Hinckley smiled when Goldman told the jury that Hinckley believes he has "possibly enhanced Foster's career."

He rapidly tapped his fingers on the defense table and shook his head when Goldman said Foster "didn't want anything to do with him" when he pursued her at Yale University in September 1980 while she was a student.

Hinckley gestured with his left hand toward Goldman and turned to one of his defense lawyers when the psychiatrist said there was no evidence that Foster was aware of Hinckley's presence, and he pounded his fist on the table when Goldman described a "cutesie card" Hinckley had sent her.

Late yesterday, after a long day of detailed testimony, Hinckley turned to his defense lawyer and indicated he felt ill. Moments later, Judge Barrington D. Parker Jr. recessed the proceeding for the day. Sources said last night that Hinckley was not seriously ill and was not examined by a doctor.

Goldman told the jury yesterday that just before the attack on Reagan, Hinckley was struggling with conflicting feelings of love and hate for Foster. In early March 1981, Hinckley stalked Foster at Yale, walking 10 to 15 feet behind her with a loaded gun in his pocket, the psychiatrist testified.

Beset with thoughts of murder and suicide, Hinckley "planned to accost her on campus" and "he was pretty sure that somebody would have to die, unless possibly she would agree to in some way come along with him or show him she cared about him in some way," Goldman said. However, he added, Hinckley never actually spoke to her then.

Goldman said Hinckley thought about kidnaping Foster and taking her to New Hampshire or Vermont, a fantasy he drew from a book about a man who abducts a woman and takes her to a "separate private world" where the woman eventually decides life is better with her abductor.

Goldman suggested that Hinckley was interested in an asexual relationship with Foster. Later in his testimony, Goldman told the jury that Hinckley regarded himself as "unable to understand why people are so interested in sex." Hinckley himself was not asexual, Goldman said, but simply had less interest in it than others.

Goldman was the fourth expert for the defense to testify that Hinckley suffered from a mental illness at the time of the shooting. According to Goldman, Hinckley has a "schizotypal personality disorder" characterized by extreme social isolation, "magical thinking" and bizarre fantasies, anxiety, blunted emotions and paranoid ideas.

Two other defense psychiatrists and a psychologist have previously testified that they also diagnosed Hinckley's condition as a form of schizophrenia. All four doctors have told the jury that as a result of Hinckley's mental illness on the day of the shooting, he was unable to abide by the law and could not appreciate that his acts were wrong.

Goldman said yesterday that Hinckley had tried everything he thought would help relieve his "intolerable" inner feelings, including medicine, psychiatry and attempts at suicide. Three weeks before the shooting, when his parents forced him out of the family home, Goldman said, Hinckley was left without choices and felt he had to "end it some way."

"It was after that that he finally lost control," Goldman testified.

Goldman said he did not believe Hinckley had any "substantial doubt" that it was illegal to shoot the President. Goldman said, however, that Hinckley perceived the people he shot as "actors in his own fantasy" of a union with Foster "in some kind of magical afterworld, or in the mind or in history.

"He didn't care about killing anybody in particular. He wanted to be united with Miss Foster and these people were intermediaries," Goldman said.

Hinckley had stalked President Carter in the fall of 1980 but was "shocked back into reality" when he was arrested at the Nashville airport with guns concealed in his luggage, Goldman testified. He realized, Goldman said, "that he was doing something out of control that was crazy."

In late 1980, Hinckley also stalked President-elect Reagan, but did not feel "the necessity to act," Goldman said, possibly feeling there might be "some other way out of his dilemma."

Under cross-examination by assistant U.S. Attorney Roger M. Adelman, Goldman acknowledged that Hinckley had traveled to Washington with guns and ammunition and had gone to Blair House with thoughts of shooting Reagan. But, Goldman said, "at that time, the balance between impulse and control was such that he didn't do it."

Goldman said yesterday that Hinckley had become preoccupied with violence as "the only way to get people to pay attention." Although no one viewed Hinckley as a violent man, Goldman said, a part of him thought "life is really kill or be killed."

Hinckley's writings were often filled with violent themes, including one poem introduced in court and called "Guns Are Fun!" in which he wrote: This gun gives me pornographic power. If I wish, the president will fall And the world will look at me in disbelief, All because I own an inexpensive gun."