Search This Blog

#Day56 #100DaysChallenge- Matlab Loops|Square root of 1 to N numbers

#Day56-Square root of 1 to N numbers

Task:

Write a code to Find Square root of 1 to N numbers
>> squarerootofgivenseries(9)

ans =

  Columns 1 through 8

    1.0000    1.4142    1.7321    2.0000    2.2361    2.4495    2.6458    2.8284

  Column 9

    3.0000

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code

function squareroot_v = squarerootofgivenseries(n)
while n>0
    squareroot_v(n)=(n)^0.5;
    n=n-1;
end
end
Sample Input and Output

>> squarerootofgivenseries(9)

ans =

  Columns 1 through 8

    1.0000    1.4142    1.7321    2.0000    2.2361    2.4495    2.6458    2.8284

  Column 9

    3.0000

>> squarerootofgivenseries(25)

ans =

  Columns 1 through 8

    1.0000    1.4142    1.7321    2.0000    2.2361    2.4495    2.6458    2.8284

  Columns 9 through 16

    3.0000    3.1623    3.3166    3.4641    3.6056    3.7417    3.8730    4.0000

  Columns 17 through 24

    4.1231    4.2426    4.3589    4.4721    4.5826    4.6904    4.7958    4.8990

  Column 25


    5.0000

Click Here for Video Description





Live Support: t.me/matlabirawen



No comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();