Sqrt of matrix - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: Sqrt of matrix ( /thread-18248.html) |

Sqrt of matrix - Amer7 - 04-11-2022 08:35 AM
Is there a command for finding a SQRT of all elements in the matrix? Like if I have a matrix (that varies in size) [attachment=10582] Like in this Example if I have 3x3 Matrix (M1)-> then I run cas.diag(M1) i will get matrix 1,9,16 now Is there a command to automatically find SQRT values of 1,9,16 ? So the answer ends up being a matrix with values 1, 3, 4 ? RE: Sqrt of matrix - StephenG1CMZ - 04-11-2022 12:43 PM
The cas sqrt(matrix) should help. RE: Sqrt of matrix - parisse - 04-11-2022 01:09 PM
Code: `apply(sqrt,[[4,1],[2,3]],matrix)` RE: Sqrt of matrix - roadrunner - 04-11-2022 01:12 PM
I think what Amer7 wants is a matrix containing the square root of each element of another matrix. If that's true then here's an example of how to do that: [[1,2],[3,4]]▶M1 MAKEMAT(√(M1(I,J)),2,2)▶M2 Now M2 contains: [[1,1.41421356237],[1.73205080757,2]] RE: Sqrt of matrix - parisse - 04-11-2022 04:13 PM
Yes, that's precisely what apply(...) does, sqrt on each element. RE: Sqrt of matrix - Amer7 - 04-11-2022 04:24 PM
@StephenG1CMZ This works when In CAS @ parisse @roadrunner It works but I have to know the size of the Matrix. The issue with my programs is when I get an assignment I never hav the same MatrixDimensions. There are a lot of calculations between the Matrices, that's why I have to write these programs. How can I call CAS in normal program. Like if I have: Code: `Begin` RE: Sqrt of matrix - StephenG1CMZ - 04-11-2022 06:07 PM
Is this syntax of any help? [code] EXPORT RT() BEGIN M1:=[1,3,9]; M1:=CAS("sqrt(M1)"); PRINT(M1); END; [\code] RE: Sqrt of matrix - Amer7 - 04-11-2022 06:24 PM
(04-11-2022 06:07 PM)StephenG1CMZ Wrote: Is this syntax of any help? Yes this works CAS("sqrt(Matrix variable)"); Thank you this will make my calculations much faster. Thank you all once again! RE: Sqrt of matrix - roadrunner - 04-12-2022 12:58 AM
(04-11-2022 04:13 PM)parisse Wrote: Yes, that's precisely what apply(...) does, sqrt on each element. Of course you are right. I failed to mention that I was referring to StephenG1CMZ's post. RE: Sqrt of matrix - Albert Chan - 04-12-2022 12:39 PM
(04-11-2022 08:35 AM)Amer7 Wrote: now Is there a command to automatically find SQRT values of 1,9,16 ? HOME> [[1, 9, 16]] .^ 0.5 → [[1, 3, 4]] This has an advantage by not going thru CAS, which may make sqrt inaccurate. HOME> M1 := [[0.398, 0.571]] HOME> M1 .^ 0.5 [[0.630872411824, 0.755645419493]] HOME> CAS("apply(sqrt, M1)") [[0.630872411823, 0.755645419492]] RE: Sqrt of matrix - StephenG1CMZ - 04-12-2022 01:50 PM
(04-11-2022 06:24 PM)Amer7 Wrote:(04-11-2022 06:07 PM)StephenG1CMZ Wrote: Is this syntax of any help? Note: Whilst sqrt(matrix) can be useful, it's not the same as applying sqrt to each element. |