Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

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

Popular Posts