As his revolution approaches its 30th birthday, President Fidel Castro has become something of an ideological renegade in the communist world, waging a lonely struggle in defense of socialist purity while others experiment with capitalist reforms.

His recent speeches underscore his resistance to change. He has adhered to a strict constructionist viewpoint with only minor variations since that New Year's Day three decades ago when he toppled a discredited dictator and proceeded to turn Cuba upside down.While the Soviet Union and other communist countries try to overcome economic stagnation by borrowing some capitalist practices, Castro remains a no-apologies defender of centralized planning and state domination of the economy.

Some analysts even foresee the possibility of the first serious Soviet-Cuban rift since the two countries became devoted allies in 1968.

The Soviets are clearly displeased with what they regard as Cuban misuse of economic aid, which has averaged about $5 billion annually in recent years.

In a recent article, the Soviet newspaper Pravda blamed Cuba for "serious imperfections" at Soviet-backed industrial projects in Cuba.

Castro, meanwhile, makes no attempt to conceal his disdain for Soviet reforms. Cuba, he has said, "must watch over the ideological purity of the revolution. . . . That is why we cannot use any methods that reek of capitalism."

He acknowledged recently that his country's future is somewhat more uncertain as a result of the Kremlin's philosophical shift.

"We can expect difficulties that may come from the enemy camp (the United States) and difficulties that may come from the camp of our own friends," he said.

In 1986, at about the time Soviet President Mikhail Gorbachev began moving toward capitalist-style reforms, Castro shut down a six-year experiment involving the sale by farmers of their produce at market rates. He was afraid that a spreading capitalist mentality and a high-income elite might take hold.

Most experts say Cuba is too valuable an ally for Moscow to cut adrift simply because of differing economic policies. Cuba provides important political support for Moscow and is widely admired throughout much of Africa and Latin America.

Cuba also serves as an indispensable base for Soviet monitoring of U.S. military and space activities. At one facility alone, 2,100 Soviet technicians engage in intercepts of U.S. communications, according to American officials.

Castro had planned a huge welcome here for Gorbachev on Dec. 9, but the visit was postponed on short notice because of the earthquake in Soviet Armenia.

Despite the apparent durability of Soviet-Cuban relations, Castro's unorthodox views have left him somewhat out of the Marxist mainstream.

While other countries look on material incentives for workers as a fact of life that must be accepted as the price for increased production, Castro believes - perhaps more firmly than before - that people should work not for personal gain but out of a sense of patriotic duty.

To the extent that Cuba is undergoing difficult economic times, Castro says the fault lies not with the system but with human frailty, the lack of revolutionary zeal. Whatever the reason, the Cuban economy has been stagnant for more than two years.

Castro, of course, never has been one to follow the crowd. He has spent a lifetime overcoming long odds.

In a recent speech, he recalled the time in December 1956 when, at the start of his guerrilla struggle, serious setbacks reduced his forces to no more than a few devoted followers. Defeat seemed imminent.

"Now we are millions," he said, using the analogy to underscore his view that seemingly insurmountable obstacles can be overcome through patience and political will.

But as Castro himself has admitted, no challenge for him has been more difficult than bringing about economic wellbeing for his countrymen.

Food and clothing are strictly rationed and there is an acute shortage of adequate housing. For transportation, Cubans must rely on buses that too often are overcrowded or make their rounds too infrequently. Cubans also complain about bureaucratic lethargy and poor service generally, in restaurants and elsewhere.

The quality of life for the average Cuban, compared with developed countries, is dreary although there appear to be few destitute Cubans. Many workers finds their jobs unfulfilling. Youths complain about a lack of recreational opportunities.

As an alternative to the drab government-controlled press, Cubans these days snatch up Spanish-language Soviet magazines which have a quality Cuban publications lack: openness.

Ofelia Espinosa, who works at a local newsstand, said some Soviet weeklies are sold out in five minutes. "Two years ago, we used to throw them out," she said.

There is no overt persecution of Cubans who practice their religion but such people have little hope of rising to positions of authority. Christmas was officially abolished years ago because the celebration interfered with the sugar harvest but there are signs of a more flexible government attitude nowadays toward that occasion.

Some families say they are discreetly doing this year what was unthinkable in previous years: putting up a Christmas tree.

While there is more tolerance for outspokenness than before, Cubans who make known their disdain for the system do so at their own risk. Worker absenteeism has been a problem for all 30 Castro years, a phenomenon that is not surprising in a country that claims to guarantee a job for everybody.