B = sqrt(X) returnsthe square root of each element of the array X.For the facets of X that are an adverse or complex, sqrt(X) producescomplex results.
You are watching: How to do square root in matlab
The sqrt function’s domain includesnegative and complicated numbers, which have the right to lead to unexpected resultsif used unintentionally. For an unfavorable and facility numbers z= u + i*w, the complex square root sqrt(z) returns
sqrt(r)*(cos(phi/2) + 1i*sin(phi/2))
where r = abs(z) is the radius and phi= angle(z) is the phase angle on the closeup of the door interval -pi.
If you want an adverse and facility numbers come return error messagesrather 보다 return complicated results, usage realsqrt instead.
Square root of Vector aspects
Open Live Script
Create a row vector comprise both an adverse and confident values.
X = -2:2
X = 1×5 -2 -1 0 1 2
Compute the square root of each element of X.
Y = sqrt(X)
Y = 1×5 complex 0.0000 + 1.4142i 0.0000 + 1.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 1.4142 + 0.0000i
X — Input array scalar | vector | procession | multidimensional array
Input array, stated as a numeric scalar, vector, matrix,or multidimensional array.
Data Types: single | doubleComplex Number Support: Yes
For real inputs, sqrt has a few behaviors the differ native those recommended in the IEEE®-754 Standard. In particular, an adverse inputs produce complex results instead of NaN.
sqrt(X) for X
Tall Arrays Calculate with arrays that have an ext rows 보다 fit in memory.
This function totally supports tall arrays. Formore information, check out Tall Arrays.
C/C++ password Generation generate C and C++ code making use of MATLAB® Coder™.
Usage notes and limitations:
Simulation to produce an error. Created standalonecode returns NaN as soon as the input value x isreal, yet the output should be complex. To get the complicated result,make the entry value complicated by passing in complex(x).
If you generate code for independent targets and also the input come sqrt in your MATLAB code is not a constant, the worth that the produced code returns for sqrt(-0) is similar to the value that the traditional library duty of your C/C++ compiler returns. If the standard library function complies v the IEEE-754 Standard, the generated code return -0.
GPU code Generation generate CUDA® code for NVIDIA® GPUs making use of GPU Coder™.
Usage notes and limitations:
Simulation produce an error. Created standalone password returns NaN once the input value x is real, however the output have to be complex. To obtain the facility result, make the intake value facility by happen in complex(x).
Thread-Based environment Run code in the background using MATLAB® backgroundPool or advice code with Parallel computing Toolbox™ ThreadPool.
This function completely supports thread-based environments. For an ext information, view Run MATLAB features in Thread-Based Environment.
GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel computing Toolbox™.
Usage notes and also limitations:
If the calculation of the duty running top top the GPU have the right to be complex, climate you must explicitly specify its input disagreements as complex. For much more information, see occupational with complex Numbers on a GPU (Parallel computer Toolbox).
For more information, check out Run MATLAB functions on a GPU (Parallel computing Toolbox).
Distributed ArraysPartition large arrays throughout the linked memory of her cluster using Parallel computer Toolbox™.
This function fully supports distributed arrays. For more information, view Run MATLAB attributes with spread Arrays (Parallel computing Toolbox).
nthroot | sqrtm | realsqrt
Introduced prior to R2006a
You have a modified variation of this example. Execute you desire to open up this instance with your edits?
No, overwrite the modified version Yes
You clicked a connect that synchronizes to this MATLAB command:
operation the command through entering the in the MATLAB Command Window. Net browsers carry out not assistance MATLAB commands.
select a net Site
Choose a net site to gain translated contents where easily accessible and see neighborhood events and offers. Based on your location, us recommend that you select: .select web site
You can likewise select a web site native the adhering to list:
How come Get ideal Site Performance
Select the China website (in Chinese or English) for ideal site performance. Other jonathanlewisforcongress.com country sites are not optimized because that visits from her location.
See more: Step By Step Guide For How To Project From Laptop To Wall Without Projector
Contact your regional office
Introducing Deep finding out with MATLABDownload ebook
Accelerating the speed of engineering and science
jonathanlewisforcongress.com is the top developer the mathematical computing software because that engineers and also scientists.