Mean square root error from different files

For example, I have files called A.txt and B.txt.
A.txt

#x yj
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

B.txt

#x ^yj
1 1 
2 8
3 27
4 64
5 125
6 216
7 343
8 512
9 729
10 1000

I would like to count the mean square root error, which has the formula exactly the same with the picture.

So far, I have this code to combine them:

#! /usr/bin/perl -w

use strict;

open FP1,"A.txt";
open FP2,"B.txt";
my ($l1,$l2);
while(1)
{
  $l1=<FP1>; chomp $l1;
  $l2=<FP2>; chomp $l2; 
  last unless(defined $l1 or defined $l2);
  print "$l1 $l2\n";
}
close FP2;
close FP1;

After it combine it will become this text file:

1 1 1 1
2 4 2 8
3 9 3 27
4 16 4 64
5 25 5 125
6 36 6 216
7 49 7 343
8 64 8 512
9 81 9 729
10 100 10 1000

The column#2 = yj and column#4 = ^yj. Any idea?

You can feed them into another script to print each line and for each line N the cumulative RMSE so far, holding the sigma in a variable that grows with each line.

Without thinking too much about your formula, but it looks like you are simply trying to paste file-a and file-b together. If so, simply use the

paste

command