sqrt
result = sqrt(x)
Input: x · Output: result
What it is
Elementwise square root. x is a scalar, Vec, or Mat/Signal; a negative element gives NaN (there is no automatic promotion to a complex result).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sqrt(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns the same shape as x. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
unsafe as n_failed
y = sqrt(-1) # NaN, not an error -- just continues
z = [1,2] + [1,2,3] # a real error -- logged, counted, continues anyway
print("still runs")
end
print("failures = {n_failed}")
from tour
pi_val = 3.14159265
print("pi = {pi_val:.2f}")
print("pi rounded = {pi_val:.0f}")
print("expr = {2+3*4}")
print("nested = {sqrt(16) + 1}")
v = [1,2,3]
print("vec sum = {sum(v):.1f}")
output
pi = 3.14 pi rounded = 3 expr = 14 nested = 5 vec sum = 6.0
from tour
tic()
for i in 1 to 1000000
x = sqrt(i)
end
elapsed_s = toc()
print("took {elapsed_s:.4f}s")
output
took 0.0079s
from repl-diagnostics
A = randn(60, 200, seed = 7) / sqrt(60)
print("coherence {coherence(A):.3f}, provable sparsity {cs_guarantee(A)}")
output
coherence 0.558, provable sparsity 1
from compressed-sensing