# Square root for each matrix/vector cell?

2 replies to this topic

### #1 MarioR

MarioR

Newbie

• Members
• 7 posts

• Calculators:

Posted 21 November 2016 - 08:46 PM

Hallo,

the next problem.

I have an vector or a matrix in which each cell is a square of a number. Now i need a matrix in which each cell is the square root of the source matrix cell.

Example:

4   9  16         2  3  4

25 36    9   =>  5  6  3

36 49  64         6  7  8

The equal problem is "example" backwards (sqare of each cell).

regards Mario

### #2 MarioR

MarioR

Newbie

• Members
• 7 posts

• Calculators:

Posted 21 November 2016 - 10:36 PM

Hello,

i have make a litle progam for this, but it is litle bit slowly:

```local matCoMax,matRoMax
local matCo,matRo
colDim(mat)⇒matCoMax
rowDim(mat)⇒matRoMax
If matCoMax>0
Then
If matRoMax>0
Then
For 1⇒matCo To matCoMax
For 1⇒matRo To matRoMax
srt(mat[matRo,matCo])⇒mat[matRo,matCo]
Next
Next
Return mat
IfEnd
IfEnd
```

Is there no faster solution?

regards Mario

Edited by MarioR, 21 November 2016 - 11:09 PM.

### #3 pan.gejt

pan.gejt

Casio Freak

• Members
• 244 posts
• Gender:Male
• Location:CZ

• Calculators:
.

Posted 22 November 2016 - 06:20 AM

Another 2 solutions

the 1st solutions- input all elements in program, dimension 3×3

ClrText

Input A
Input B
Input C
Input D
Input E
Input F
Input G
Input H
Input I
sqrt({A,B,C})->list1
sqrt({D,E,F})->list2
sqrt({G,H,I})->list3
listToMat(list1,list2,list3)->A
Print "SQRT OF ELEMENTS IS"
Print trn(A)

notice: sqrt is calculated for positive roots only

trn means transposition of matrix A

the templates are not working in program, so the matrix is displayed in 1 row - [[A,B,C],[D,E,F],[G,H,I] ]

if you want TO display the matrix as the template you need to switch from program to main application

or you can use parameter variable box and in this case you don't need the Input commands. Just enter into box all variables A,B,C,D,E,F,G,H,I and before running the program fill numbers 4,9,16,25,36,9,36,49,64 into the box parameter

ClrText

sqrt({A,B,C})->list1
sqrt({D,E,F})->list2
sqrt({G,H,I})->list3
listToMat(list1,list2,list3)->A
Print "SQRT OF ELEMENTS IS"
Print trn(A)

----------------------------------------------

the 2nd solution - all elements are entered into matrix A in main application

ClrText
colDim(A)->n
n-2->o
n-1->p
trn(A)->A
matToList(A,o)->listo
matToList(A,p)->listp
matToList(A,n)->listn
listToMat(sqrt(listo),sqrt(listp),sqrt(listn))->B
Print "SQRT OF ELEMENTS IS"
Print B

Edited by pan.gejt, 22 November 2016 - 06:32 AM.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users