Ronald Reagan is the undisputed frontrunner in Virginia, but President Carter remains within striking distance with a substantial segment of undecided voters holding the key to the state's 12 electoral votes, according to three new state polls and interviews with political analysts.

The first poll, released today by The Richmond Times-Dispatch, shows Reagan leading Carter by 36 percent to 31 percent, with 5 percent for independent John Anderson and a whopping 27 percent of the state's electorate undecided. Compared with the newspaper's first poll a month ago, which showed Reagan ahead by 40 to 34, the former California governor's margin has dropped one point.

More significant, however, may be the large blocs that have defected from all three candidates and moved to the ranks of the undecided. Last month only 18 percent of those interviewed by the newspaper considered themselves undecided.

Reagan campaign officials here immediately disputed the poll and said their own survey, which they refused to release, shows Reagan's margin over Carter at a more comfortable 10 points, with about 15 percent undecided. The GOP poll, which does not show any erosion in Reagan's support here, was conducted by North American Marketing Corp. president William A. Royall Jr., a Republican with established credentials as a professional pollster.

Another highly respected analyst, University of Virginia political scientist Larry Sabato, completed a poll this week that is said to reflect Royall's findings showing Reagan substantially ahead in the state. Sabato said he would not release his poll's results until later in the week.

In a Maryland poll published today in the Baltimore Sun, Carter leads Reagan 42 to 34 percent with Anderson at 10 percent. The poll found only 13 percent undecided, a sharp drop from other polls in recent weeks. The poll was taken between Oct. 9 and 18 and also showed incumbent Republican Sen. Charles McC. Mathias with a commanding 61-to-22 percent lead for reelection over Democratic State Sen. Edward Conroy of Prince George's County.

The discrepancies between the Virginia polls can be reconciled to some extent by taking into account their margins of error, which in each poll are at least 3 percent. The Times-Dispatch survey, for example, taken Oct. 10 to 19 of 624 registered voters, has a 4-point error margin, meaning Reagan could be ahead by as much as 40 to 27, or behind by as much as 35 to 32.

But despite the discrepancies, all three polls suggest victory for Reagan is still not certain in a conservative southern state that Reagan's supporters hoped long ago to safely lock in their column. Virginia has not given a majority to a Democratic presidential candidate since Lyndon Johnson in 1964.

"Let's face it, if Ronald Reagan can't easily take Virginia, or even if it's nip and tuck, then he doesn't stand a prayer of winning anywhere on the East Coast except maybe Vermont or New Hampshire," said Sabato.

Reagan state campaign chairman John Alderson said the Times-Dispatch poll showing Reagan slipping was "just not for real . . . it contradicts every survey that's come across my desk for the last 30 days."

"On election day," Alderson added, "Ronald Reagan's going to get 53 percent of the vote here and Anderson 5 and Jimmy's going to get the rest."

Another Republican analyst suggested that the poll showing Reagan in a close race will actually help the GOP candidate. "The T-D poll suits me fine because I want this election to look closer than it is so that Virginians will get out and vote for Reagan," he said.

But Bill Albers, Carter state coordinator, said his own Virginia surveys, conducted by Democratic pollster Patrick Caddell, show the president gaining ground on Reagan.

"Two-and-a-half weeks ago Patrick had us 10 points down and now he says we're less than 5," said Albers, who rfused to release the Caddell polls. He conceded Caddell's findings were based on only 450 registered voters, leaving a wider error margin than other state polls, but contended, "Patrick knows what he's doing and he's very seldom wrong."