[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #48950] functions cart2pol, cart2sph, pol2cart
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #48950] functions cart2pol, cart2sph, pol2cart, sph2cart fail in some cases |
Date: |
Tue, 30 Aug 2016 12:19:33 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 |
URL:
<http://savannah.gnu.org/bugs/?48950>
Summary: functions cart2pol,cart2sph,pol2cart,sph2cart fail
in some cases
Project: GNU Octave
Submitted by: None
Submitted on: Tue 30 Aug 2016 12:19:31 PM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name:
Originator Email: address@hidden
Open/Closed: Open
Discussion Lock: Any
Release: 4.0.3
Operating System: Any
_______________________________________________________
Details:
These functions fail in some cases with mixed scalar and non-scalar inputs.
For example:
>> cart2pol (1:4, 2:5, 3)
error: horizontal dimensions mismatch (4x2 vs 1x1)
error: called from
cart2pol at line 79 column 11
>> cart2pol (1, 2, 3:6)
error: horizontal dimensions mismatch (1x2 vs 4x1)
error: called from
cart2pol at line 79 column 11
>> pol2cart (1:4, 2:5, 3)
error: horizontal dimensions mismatch (4x2 vs 1x1)
error: called from
pol2cart at line 79 column 7
>> pol2cart (1, 2, 3:6)
error: horizontal dimensions mismatch (1x2 vs 4x1)
error: called from
pol2cart at line 79 column 7
>> cart2sph (1, 2, 3:6)
error: horizontal dimensions mismatch (1x1 vs 4x1)
error: called from
cart2sph at line 71 column 11
>> sph2cart (1:4, 2, 3)
error: horizontal dimensions mismatch (4x2 vs 1x1)
error: called from
sph2cart at line 71 column 7
Possible solution:
diff --git a/cart2pol.m b/cart2pol.m
--- a/cart2pol.m
+++ b/cart2pol.m
@@ -72,6 +72,8 @@
endif
endif
+ [err, x, y, z] = common_size (x, y, z);
+
theta = atan2 (y, x);
r = sqrt (x .^ 2 + y .^ 2);
@@ -112,7 +114,7 @@
%! [t, r, z2] = cart2pol (x, y, z);
%! assert (t, [0, 0, 0], eps);
%! assert (r, x, eps);
-%! assert (z, z2);
+%! assert ([0, 0, 0], z2);
%!test
%! x = 0;
@@ -121,15 +123,15 @@
%! [t, r, z2] = cart2pol (x, y, z);
%! assert (t, [0, 1, 1]*pi/2, eps);
%! assert (r, y, eps);
-%! assert (z, z2);
+%! assert ([0, 0, 0], z2);
%!test
%! x = 0;
%! y = 0;
%! z = [0, 1, 2];
%! [t, r, z2] = cart2pol (x, y, z);
-%! assert (t, 0);
-%! assert (r, 0);
+%! assert (t, [0, 0, 0]);
+%! assert (r, [0, 0, 0]);
%! assert (z, z2);
%!test
diff --git a/cart2sph.m b/cart2sph.m
--- a/cart2sph.m
+++ b/cart2sph.m
@@ -63,6 +63,8 @@
endif
endif
+ [err, x, y, z] = common_size (x, y, z);
+
theta = atan2 (y, x);
phi = atan2 (z, sqrt (x .^ 2 + y .^ 2));
r = sqrt (x .^ 2 + y .^ 2 + z .^ 2);
diff --git a/pol2cart.m b/pol2cart.m
--- a/pol2cart.m
+++ b/pol2cart.m
@@ -72,6 +72,8 @@
endif
endif
+ [err, theta, r, z] = common_size (theta, r, z);
+
x = r .* cos (theta);
y = r .* sin (theta);
@@ -130,7 +132,7 @@
%! [x, y, z2] = pol2cart (t, r, z);
%! assert (x, [1, 2, 3], eps);
%! assert (y, [0, 0, 0] / sqrt (2), eps);
-%! assert (z, z2);
+%! assert ([1, 1, 1], z2);
%!test
%! P = [0, 0; pi/4, sqrt(2); pi/4, 2*sqrt(2)];
diff --git a/sph2cart.m b/sph2cart.m
--- a/sph2cart.m
+++ b/sph2cart.m
@@ -63,6 +63,8 @@
endif
endif
+ [err, theta, phi, r] = common_size (theta, phi, r);
+
x = r .* cos (phi) .* cos (theta);
y = r .* cos (phi) .* sin (theta);
z = r .* sin (phi);
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?48950>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #48950] functions cart2pol, cart2sph, pol2cart, sph2cart fail in some cases,
anonymous <=