How to resolve the algorithm Averages/Root mean square step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Root mean square step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
Compute the Root mean square of the numbers 1..10.
The root mean square is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Root mean square step by step in the ALGOL 68 programming language
Source code in the algol programming language
# Define the rms PROCedure & ABS OPerators for LONG... REAL #
MODE RMSFIELD = #LONG...# REAL;
PROC (RMSFIELD)RMSFIELD rms field sqrt = #long...# sqrt;
INT rms field width = #long...# real width;
PROC crude rms = ([]RMSFIELD v)RMSFIELD: (
RMSFIELD sum := 0;
FOR i FROM LWB v TO UPB v DO sum +:= v[i]**2 OD;
rms field sqrt(sum / (UPB v - LWB v + 1))
);
PROC rms = ([]RMSFIELD v)RMSFIELD: (
# round off error accumulated at standard precision #
RMSFIELD sum := 0, round off error:= 0;
FOR i FROM LWB v TO UPB v DO
RMSFIELD org = sum, prod = v[i]**2;
sum +:= prod;
round off error +:= sum - org - prod
OD;
rms field sqrt((sum - round off error)/(UPB v - LWB v + 1))
);
main: (
[]RMSFIELD one to ten = (1,2,3,4,5,6,7,8,9,10);
print(("crude rms(one to ten): ", crude rms(one to ten), new line));
print(("rms(one to ten): ", rms(one to ten), new line))
)
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Entropy step by step in the Racket programming language
You may also check:How to resolve the algorithm P-Adic numbers, basic step by step in the Raku programming language
You may also check:How to resolve the algorithm Empty string step by step in the min programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the Ada programming language