President Reagan yesterday ended a week that shocked the nation and plunged his administration into crisis convinced that he had succeeded in mobilizing public opinion on behalf of both the invasion of Grenada and his policies in the Middle East.

"He thinks he turned the tide, and the calls we're getting and the early polls bear this out," one official said.

Aides close to the president said that Reagan, who earlier in the week appeared stunned and shaken by the killing of more than 225 U.S. Marines in Beirut, was in an upbeat mood because he believed his nationally televised speech Thursday night defending the presence of U.S. Marines in Lebanon and Grenada had won popular approval.

At the end of a week in which the United States counted more military casualties than at any time since the worst fighting of the Vietnam war, Reagan demonstrated this optimism Friday in a carefully staged ceremony that was reminiscent of a triumphant political campaign.

Usually, departure ceremonies for Camp David are as eventful as an exchange of diplomatic credentials. This time, the president's men assembled 200 flag-waving staff members on the White House South Lawn to cheer his weekend leave-taking.

Conservative speechwriter Dana Rohrabacher held aloft a big poster with "Your Finest Hour" written on it and a flag stuck in the top corner. Presumably referring to the Grenada invasion, he was paraphrasing words that British Prime Minister Winston Churchill applied early in World War II to the Royal Air Force pilots who held off the German Luftwaffe.

Reagan appeared stirred by the demonstration of support. He went down the entire rope line, shaking hands with many people and repeatedly smiling and waving. There was not a hint of solemnity or anxiety. He looked much as he did in 1980 when he had just won a primary and was heading for the next one.

Aides said this public demonstration of Reagan's mood was matched by a private jubilation when he received the results of an ABC "Nightline" survey of 250 people Thursday night showing a sharp turnaround in attitudes on Lebanon as the result of his speech a few hours earlier. Support for U.S. policies in Lebanon jumped from slightly better than an even split to 4-to-1 backing, with even higher support for the Grenada invasion.

Reagan had been uncharacteristically tense before the speech, aides said, recognizing that the address was as important as any he has given during his presidency.

The mood was in sharp contrast to the one of last weekend. On Saturday, Reagan had been diverted from a golf game in Augusta, Ga., to talk to a gunman who had taken two of his aides hostage in the course clubhouse. The aides and others who were briefly captured were released unharmed, but the incident reportedly upset Nancy Reagan.

Reagan was already tired--although no one outside his inner circle knew it at the time--because he had been awakened at 5:15 that morning and been told about the request of eastern Caribbean nations for assistance against the government of Grenada. Aides said that the president, who had long considered Grenada a potentially dangerous outpost of Marxism in the Caribbean, readily agreed to the request.

That afternoon, the president discussed both the Grenada situation and the golf course hostage incident with his top aides and decided against returning to Washington. But he was awakened again after a few hours of sleep by national security affairs adviser Robert C. McFarlane, this time at 2:27 a.m. Sunday, and informed of the suicide bombing in Beirut, which had occurred less than two hours earlier.

Reagan was up from then on, returning to Washington early Sunday morning and plunging into a two-hour National Security Council meeting, the first of two held that day. One aide said he seemed "exhausted."

Whether he napped in midday has not been announced, but Reagan appeared fresher in the second, afternoon NSC meeting, this one devoted largely to Grenada. The invasion plan was still a secret in the United States, though not in Grenada, and reporters were told and also assumed that the NSC meeting had been devoted to Lebanon.

Deputy chief of staff Michael K. Deaver said that the "pain and hurt" of the Beirut bombing showed on the president's face in the NSC meetings, in which Reagan spent more time Sunday than on any other day of his presidency.

As is usual in the Reagan White House, the president delegated many decisions to others. His involvement after giving the initial go-ahead on Grenada, according to one senior official, consisted largely of "keeping posted" and letting the military operate the war.

But aides said that he spoke up forcefully in the second meeting Sunday devoted largely to a question of whether the Grenada attack should be delayed because of the Beirut bombing, and he agreed that a terrorist act in the Middle East shouldn't stop an invasion in the Caribbean.

Deaver said that Reagan went to bed that night "a tired and unhappy man," shaken by the death of so many U.S. Marines.

Throughout his political career, Reagan has often been suspected of working too little and resting too much. "Show me an executive who works long, hard hours, and I'll show you a bad executive," he said during one interview in the 1980 campaign.

But Reagan was not accused by anyone of underworking this past week. The question about him, raised only in whispers by his loyal staff, was whether he understood that Mideast negotiators had not yet written a script in which the U.S. involvement in Lebanon necessarily has a happy ending.

"We don't have an easy way of getting out of there," said one aide at week's end. "I think the president knows that."

The turning point for Reagan in the week, according to one aide, was the moment when the first American students from the St. George's University School of Medicine in Grenada arrived safely on U.S. soil and one of them kissed the ground. He also was buoyed by the reaction in Congress and the symbol of bipartisan support extended to him by the Democratic leaders of the House.

One of the few clouds intruding on the happy horizon of Reagan's optimism was the negative reaction of European leaders, whose opinions have always been secondary to this president when compared to domestic public opinion. The one exception to this rule has been British Prime Minister Margaret Thatcher, a friend and ally of the president on most issues but an opponent of the Grenadan invasion.

Reagan called Thatcher on Thursday for the second time during the week. Peter Osnos, The Washington Post's London correspondent, reported that he assured her that U.S. forces would be withdrawn as quickly as possible and that Thatcher, in return, softened her tone of opposition and was saying, "We are very grateful to the United States."

Reagan's favorite story on the campaign trail is about two boys, one an incurable pessimist and the other an equally incurable optimist, who are taken by their parents to a psychologist for treatment.

The pessimist is placed in a room of shiny new toys, but when he is visited after an hour he is crying, not playing with any of them out of fear that they might break.

The optimistic boy is placed in a room of horse manure, and when his parents come in he is cheerfully shoveling away, saying, "I know there has to be a pony in here someplace."

Within the White House, at the end of this difficult week, there was no shortage of those who were optimistically trying to find the pony. And they were led by Ronald Reagan.

White House spokesman Larry Speakes, who earlier in the week sent a memo to White House chief of staff James A. Baker III saying that the administration's credibility had been compromised and whose own credibility has been challenged by representatives of most major news organizations, treated reporters with quotes from telegrams and telephone calls in the wake of the president's speech.

One telegram, from New York, said: "I support you fully in Lebanon and Grenada, although I do not know where my son is. He is a U.S. Marine and although his life may be in jeopardy, we fully support you."

When a reporter asked Friday if it was true that the president, on the verge of the largest U.S. invasion since Vietnam, had slept for an hour after the Marines landed in Grenada at 5 a.m., Speakes refused to answer, saying that the question made anger "well up" in him. But one of the president's staunchest aides, apprised afterward of the colloquy, said the reporter was right.