#!/usr/bin/perl
#
# Given components of a vector, and their uncertainties, 
#   compute magnitude, and its uncertainty.
#
# MWR 1/22/2026

use POSIX;
$debug = 1;

while (1) {

		  printf "gimme X +/- dX : \n";
		  $line = <STDIN>;
        if ($line eq "q") {
          exit(0);
        }
    
        $line = " " . $line;
		  @words = split(/\s+/, $line);
		  $x = $words[1];
		  $dx = $words[2];


		  printf "gimme Y +/- dY : \n";
		  $line = " " . <STDIN>;
		  @words = split(/\s+/, $line);
		  $y = $words[1];
		  $dy = $words[2];


		  # calc mag
		  $mag = sqrt($x*$x + $y*$y);

		  # calc uncert in mag
		  $top = abs($x)*$dx + abs($y)*$dy;
		  $bot = $mag;
		  $mag_uncert = $top / $bot;

		  printf " magnitude  %6.2f  +/- %6.2f \n", $mag, $mag_uncert;

}



