Close. In perl, ^ is the XOR operator; use ** for exponents. I cleaned up the program & added units:
<pre><font class="small">code:</font><hr>#!/usr/bin/perl
$m = 1; # kg
$A = 1; # m
$t = 1; # s
$c = 313000000; # m/s
$pi = 3.14159265358979;
while (1) {
print "Mass [kg]: ";
$m = <STDIN>;
chomp $m;
if ($m == "") { exit; }
print "Frequency [Hz]: ";
$freq = <STDIN>;
chomp $freq;
if ($freq == "") { exit; }
$w = 2*$pi*$freq;
&calc($m,$w)
}
sub calc {
$m = shift;
$w = shift;
$x = $A * sin($w * $t);
$v = $A * $w * cos($w * $t);
$a = -1 * ($w ** 2) * $x;
$F = -1 * $m * $x * ($w ** 2);
$U = 0.5 * $m * ($A ** 2) * ($w ** 2) * (cos($w * $t) ** 2);
$vavg = $w * $A;
$E = 0.5 * $m * ($w ** 2) * ($A ** 2) * (sin($w * $t) ** 2);
$Etot = 0.5 * $m * ($vavg ** 2);
$mavg = $m / sqrt(1 - ($vavg / $c) ** 2);
$tdi = $t / sqrt(1 - ($v / $c) ** 2);
$tdavg = $t / sqrt(1 - ($vavg / $c) ** 2);
$per = 100 * ($mavg - $m) / $m;
print qq~
mass of $m kg
frequency of $freq Hz ($w rad/s)
Amplitude of $A m
After $t second...
x = $x m
v = $v m/s
a = $a m/s/s
F = $F N
U = $U J
E = $E J
Etot = $Etot J
vavg = $vavg m/s
mavg = $mavg kg
tdi = $tdi s
tdavg = $tdavg s
Average mass increase: $per %
~;
}</pre><hr>
Example output:
<pre><font class="small">code:</font><hr>Mass [kg]: 100
Frequency [Hz]: 10000000
mass of 100 kg
frequency of 10000000 Hz (62831853.0717958 rad/s)
Amplitude of 1 m
After 1 second...
x = -6.59310333966933e-008 m
v = 62831853.0717957 m/s
a = 260285286.952149 m/s/s
F = 26028528695.2149 N
U = 1.97392088021786e+017 J
E = 858.043897335502 J
Etot = 1.97392088021787e+017 J
vavg = 62831853.0717958 m/s
mavg = 102.077855846659 kg
tdi = 1.02077855846659 s
tdavg = 1.02077855846659 s
Average mass increase: 2.07785584665892 %</pre><hr>
In this example, we see that a 100 kg mass vibrating at 10 MHz should gain about 2 kg of mass. Of course, the amplitude is 1 m, which is very impractical. At more realistic values of A, the mass increase is negligible.
<pre><font class="small">code:</font><hr>#!/usr/bin/perl
$m = 1; # kg
$A = 1; # m
$t = 1; # s
$c = 313000000; # m/s
$pi = 3.14159265358979;
while (1) {
print "Mass [kg]: ";
$m = <STDIN>;
chomp $m;
if ($m == "") { exit; }
print "Frequency [Hz]: ";
$freq = <STDIN>;
chomp $freq;
if ($freq == "") { exit; }
$w = 2*$pi*$freq;
&calc($m,$w)
}
sub calc {
$m = shift;
$w = shift;
$x = $A * sin($w * $t);
$v = $A * $w * cos($w * $t);
$a = -1 * ($w ** 2) * $x;
$F = -1 * $m * $x * ($w ** 2);
$U = 0.5 * $m * ($A ** 2) * ($w ** 2) * (cos($w * $t) ** 2);
$vavg = $w * $A;
$E = 0.5 * $m * ($w ** 2) * ($A ** 2) * (sin($w * $t) ** 2);
$Etot = 0.5 * $m * ($vavg ** 2);
$mavg = $m / sqrt(1 - ($vavg / $c) ** 2);
$tdi = $t / sqrt(1 - ($v / $c) ** 2);
$tdavg = $t / sqrt(1 - ($vavg / $c) ** 2);
$per = 100 * ($mavg - $m) / $m;
print qq~
mass of $m kg
frequency of $freq Hz ($w rad/s)
Amplitude of $A m
After $t second...
x = $x m
v = $v m/s
a = $a m/s/s
F = $F N
U = $U J
E = $E J
Etot = $Etot J
vavg = $vavg m/s
mavg = $mavg kg
tdi = $tdi s
tdavg = $tdavg s
Average mass increase: $per %
~;
}</pre><hr>
Example output:
<pre><font class="small">code:</font><hr>Mass [kg]: 100
Frequency [Hz]: 10000000
mass of 100 kg
frequency of 10000000 Hz (62831853.0717958 rad/s)
Amplitude of 1 m
After 1 second...
x = -6.59310333966933e-008 m
v = 62831853.0717957 m/s
a = 260285286.952149 m/s/s
F = 26028528695.2149 N
U = 1.97392088021786e+017 J
E = 858.043897335502 J
Etot = 1.97392088021787e+017 J
vavg = 62831853.0717958 m/s
mavg = 102.077855846659 kg
tdi = 1.02077855846659 s
tdavg = 1.02077855846659 s
Average mass increase: 2.07785584665892 %</pre><hr>
In this example, we see that a 100 kg mass vibrating at 10 MHz should gain about 2 kg of mass. Of course, the amplitude is 1 m, which is very impractical. At more realistic values of A, the mass increase is negligible.