QUESTION: In a video game series called ''Mass Effect'' the capital ships (dreadnought) of Systems Alliance (The largest human government in ME universe) can fire a 20 kg magnetic projectile to 4025km/second velocity by using an 800 m long railgun. This projectile impacts with kinetic energy of 162006250000000 joules which is 38,72 kilotons of tnt translated. What would the problems be in designing this kind of weapon for our future space ships? Is any theoretical source of energy sufficient enough to power this gun? And what other problems are there?
ANSWER: Simple enough. First: weight. Orbital things have to be as small as possible, a railgun would be ridiculously heavy. Second you already hit on: power. You'd need a nuclear reactor. Those are not light, and there's nothing to emergency cool them in space if something goes wrong. You'd need lots and lots of power to shoot more than once in a while, so a BIG honkin' reactor would be your first choice. Solar won't cut it for what you're talking about, even in space. Third: stability. Stable rails would have to be insanely heavy, which brings us back to weight. Then you'd have to discharge your switch so fast you'd have to make sure it didn't explode (common problem among railguns, actually). I'm sure there are a host of other problems...but don't nukes seem easier for a measly 38 kT? That's a simple tactical nuke, they used to make them 1000x more powerful than that.
---------- FOLLOW-UP ----------
QUESTION: So a nuclear reactor (possibly fusion) or antimatter (if antimatter can be produced in usable quantities) should be able to power this weapon? And could the projectile survive momentum of this weapon because I've read that when you accelerate something in a railgun to a fraction of lightspeed the energy transferred into the projectile is so enormous that the projectile melts and becomes plasma. And when you said that wouldn't nukes be easier than these railguns. In space there is no pressure to carry the shockwave of a nuke so wouldn't a kinetic energy weapon be better than a nuke in ship to ship combat? And thank you for your answer.
A fission reactor is just fine to power it, and with current technology, far more practical. Projectile survivability depends on projectile design, of course. A railgun will not approach a fraction of lightspeed. The speed you mention is only 1% of the speed of light...about 4 million times the energy (2000-ish times the speed) of the one the navy tested in the late 2000's. Yes, that probably would destroy whatever rails and conductors you had it built of, so scale back the whole idea even if you're in space.
Nukes are superior in space, however. If the nuclear weapon detonates on your enemy's hull there's plenty of material to vaporize and conduct away energy. If it's far from your ship you don't get the same blowback at all. Nuclear weapons implode from radiation pressure in their second stage, anyhow. Conservation of energy, that energy has to go somewhere. A close-in or slightly-penetrating blast from a space nuke will still destroy your enemy much more efficiently than a slow-to-fire, slow-to-aim, low-impact railgun (which will just tear a clean hole through a ship and not really blow up) ever could. Nukes. Still the standard for destructive power.