Write a function called odd_rms that returns orms, which is the square root of t
ID: 2292210 • Letter: W
Question
Write a function called odd_rms that returns orms, which is the square root of the mean of the squares of the first nn positive odd integers, where nn is a positive integer and is the only input argument. For example, if nn is 3, your function needs to compute and return the square root of the average of the numbers 1, 9, and 25. You may use built-in functions including, for example, sum and sqrt, except for the built-in function rms, which is not allowed. DO NOT use if for while or rms commands
Explanation / Answer
clc
clear all
close all
nn=input('Enter number of odd values to be considered: ');
orms=odd_rms(nn);
fprintf('The RMs value of first %d odd square numbers is:',nn)
disp(orms)
-------------------------------------
function orms=odd_rms(nn)
temp=0;
for i=1:2:(2*nn-1)
temp=temp+i^2;
end
orms=sqrt(temp/nn);
Output:
Enter number of odd values to be considered: 5
The RMs value of first 5 odd square numbers is: 5.7446
Enter number of odd values to be considered: 3
The RMs value of first 3 odd square numbers is: 3.4157
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.