Programmatically add related products to a product in magento
devm.com.np
<?php
$productId 
Mage::getModel('catalog/product')->getIdBySku('sku');
$product Mage::getModel('catalog/product')->load($productId);

$productId1 1;
$productId2 2;

$relatedLinks = array();

$relatedLinks[$productId1] = array('position'=>'') ;
$relatedLinks[$productId2] = array('position'=>'') ;

$product->setRelatedLinkData($relatedLinks);
?>