Question

MATLAB Question:

TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is defined as the square root of n rounded to th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%%%%FUNCTION FOR PART A

function d = numdigs(n)
d = strlength(string(n));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%SCRIPT FOR PART 2

n=input('Enter a positive integer: ');
d = numdigs(n);
if rem(d,2)==0
    x0=7*10^((d-2)/2);
else
    x0=7*10^((d-1)/2);
end
xi=1/x0;
xi1=x0;
while xi~=xi1
    xi=xi1;
    xi1=floor((xi+ceil(n/xi))/2);
end
fprintf('RSR value: %d\n',xi1)
       

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%SCRIPT FOR PART 3

RSR=zeros(1,length(1000:9999));
for n=1000:9999
    d = numdigs(n);
    if rem(d,2)==0
        x0=7*10^((d-2)/2);
    else
        x0=7*10^((d-1)/2);
    end
    xi=1/x0;
    xi1=x0;
    while xi~=xi1
        xi=xi1;
        xi1=floor((xi+ceil(n/xi))/2);
    end
    RSR(n-999)=xi1;
end

Command Window >>RSR calc Enter a positive integer 1234 RSR value: 35 RSR calc Enter a positive integer: 1337 RSR value: 37 R

Add a comment
Know the answer?
Add Answer to:
MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT