-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsqrt.m
More file actions
29 lines (24 loc) · 631 Bytes
/
csqrt.m
File metadata and controls
29 lines (24 loc) · 631 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function result = csqrt(a)
% var r, theta, rootr;
% var result = new Array();
r = sqrt(a(1)*a(1) + a(2)*a(2));
theta = atan2(a(2),a(1));
rootr = sqrt(r);
result(1) = rootr*cos(0.5*theta);
result(2) = rootr*sin(0.5*theta);
% return result;
end
% function csqrt(a){
% var r, theta, rootr;
%
% var result = new Array();
%
% r = Math.sqrt(a[0]*a[0] + a[1]*a[1]);
% theta = Math.atan2(a[1],a[0]);
% rootr = Math.sqrt(r);
%
% result[0] = rootr*Math.cos(0.5*theta);
% result[1] = rootr*Math.sin(0.5*theta);
% return result;
%
% }