Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30652 > unrolled thread
| Started by | "Chris M. Thomasson" <nospam@nospam.com> |
|---|---|
| First post | 2016-06-11 10:52 -0700 |
| Last post | 2016-07-01 13:52 -0700 |
| Articles | 6 on this page of 26 — 6 participants |
Back to article view | Back to comp.lang.javascript
Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-11 10:52 -0700
Re: Impact of implicit arrays... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-12 12:16 +0200
Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-13 12:23 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-13 22:00 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.com> - 2016-06-14 17:17 -0700
Re: Impact of implicit arrays... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-15 06:55 +0200
Re: Impact of implicit arrays... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-14 22:19 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 12:47 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 14:43 -0700
Re: Impact of implicit arrays... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 00:10 +0200
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 15:28 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 15:31 -0700
Re: Impact of implicit arrays... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 11:55 +0200
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 12:23 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:14 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:16 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 18:14 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 18:46 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-21 17:35 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-21 21:08 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-21 23:09 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-23 14:38 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-24 07:16 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-25 18:03 -0700
Re: Impact of implicit arrays... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 18:24 -0700
Re: Impact of implicit arrays... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-01 13:52 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2016-06-21 23:09 -0700 |
| Message-ID | <994a5f96-b90f-4078-8626-543bf6a2e9e6@googlegroups.com> |
| In reply to | #30706 |
On Tuesday, June 21, 2016 at 11:08:39 PM UTC-5, Chris M. Thomasson wrote:
> I notice that Chrome gives me a "Reference Error: this is not defined"
> such that (alert("hello 1");) never gets called in your constructor:
> ______________________________
> constructor(re, im) {
> alert("hello 0");
> this.re = re;
> alert("hello 1");
> this.im = im;
> }
> ______________________________
>
> I must be creating (ComplexRect) objects in a totally screwed up way:
> ______________________________
> {
> var c = new ComplexRect(-.75, .09);
> alert(c.re + ", " + c.im);
> }
> ______________________________
>
> How do I create instances of (ComplexRect)?
small typo there. If a class extends another class, super() must be called before referencing "this".
> Because I like to add on extra components for fun/experimental purposes. ;^)
>
> Also, take a look at my (ct_complex_roots) function:
> _________________________________________
> function ct_complex_roots(c, p)
> {
> var l = ct_complex_abs(c);
> var s = Math.pow(l, 1.0 / p);
> var a = Math.atan2(c[1], c[0]) / p;
>
> var n = Math.ceil(Math.abs(p));
> var as = (Math.PI * 2) / p;
> var roots = [];
>
> for (var i = 0; i < n; ++i)
> {
> roots.push([Math.cos(a + as * i) * s,
> Math.sin(a + as * i) * s]);
> }
>
> return roots;
> }
> _________________________________________
>
>
> The return value from this can contain more than two objects, so, IMVHO,
> the ease of iterating the return value (roots) is very nice wrt Arrays.
I'm still missing the point here. Why not have:
class Complex{
...
root(p){...}
}
where c.roots(p) returns an Array<Complex>?
even in your example the roots array still only has two components per entry
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-06-23 14:38 -0700 |
| Message-ID | <nkhkt6$dfv$1@dont-email.me> |
| In reply to | #30708 |
On 6/21/2016 11:09 PM, Michael Haufe (TNO) wrote:
> On Tuesday, June 21, 2016 at 11:08:39 PM UTC-5, Chris M. Thomasson wrote:
[...]
> even in your example the roots array still only has two components per entry
Yup. Humm, how about the following functional addition function:
(please excuse any typos, I typed this in the newsreader)
_______________________________________
function ct_complex_add(a, b) {
var n = Math.min(a.length, b.length);
var sum = new Array(n);
for (var i = 0; i < n; ++i) {
sum[i] = a[i] + b[i];
}
return sum;
}
_______________________________________
You can call it like:
_______________________________________
{
var r = ct_complex_add([1, 2], [3, 4]);
alert("r:(" + r + ")");
return true;
}
_______________________________________
We can add extra elements to the arrays, and the function
(ct_complex_add) still works:
_______________________________________
{
var r = ct_complex_add([1, 2, 3, 4], [5, 6, 7, 8]);
alert("r:(" + r + ")");
return true;
}
_______________________________________
We can add extra elements or even pass arrays that have different number
of elements:
_______________________________________
{
var r = ct_complex_add([1, 2, 3], [4, 5, 6, 7]);
alert("r:(" + r + ")");
return true;
}
_______________________________________
What do you think of this? Is it a bit too contrived?
:^o
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2016-06-24 07:16 -0700 |
| Message-ID | <bc601b80-611c-4775-9343-f425f0de0326@googlegroups.com> |
| In reply to | #30715 |
On Thursday, June 23, 2016 at 4:38:51 PM UTC-5, Chris M. Thomasson wrote:
> On 6/21/2016 11:09 PM, Michael Haufe (TNO) wrote:
> > On Tuesday, June 21, 2016 at 11:08:39 PM UTC-5, Chris M. Thomasson wrote:
> [...]
> > even in your example the roots array still only has two components per entry
>
> Yup. Humm, how about the following functional addition function:
>
> (please excuse any typos, I typed this in the newsreader)
> _______________________________________
> function ct_complex_add(a, b) {
> var n = Math.min(a.length, b.length);
>
> var sum = new Array(n);
>
> for (var i = 0; i < n; ++i) {
> sum[i] = a[i] + b[i];
> }
>
> return sum;
> }
> _______________________________________
>
>
> You can call it like:
> _______________________________________
> {
> var r = ct_complex_add([1, 2], [3, 4]);
> alert("r:(" + r + ")");
> return true;
> }
> _______________________________________
>
>
> We can add extra elements to the arrays, and the function
> (ct_complex_add) still works:
>
> _______________________________________
> {
>
> var r = ct_complex_add([1, 2, 3, 4], [5, 6, 7, 8]);
> alert("r:(" + r + ")");
> return true;
> }
> _______________________________________
>
>
>
>
> We can add extra elements or even pass arrays that have different number
> of elements:
> _______________________________________
> {
>
> var r = ct_complex_add([1, 2, 3], [4, 5, 6, 7]);
> alert("r:(" + r + ")");
> return true;
> }
> _______________________________________
>
>
>
> What do you think of this? Is it a bit too contrived?
What do the arrays represent in this case? Before it was [Re,Im]
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-06-25 18:03 -0700 |
| Message-ID | <nkn9kd$kfc$1@dont-email.me> |
| In reply to | #30718 |
On 6/24/2016 7:16 AM, Michael Haufe (TNO) wrote:
> On Thursday, June 23, 2016 at 4:38:51 PM UTC-5, Chris M. Thomasson wrote:
>> On 6/21/2016 11:09 PM, Michael Haufe (TNO) wrote:
>>> On Tuesday, June 21, 2016 at 11:08:39 PM UTC-5, Chris M. Thomasson wrote:
>> [...]
>>> even in your example the roots array still only has two components per entry
>>
>> Yup. Humm, how about the following functional addition function:
>>
>> (please excuse any typos, I typed this in the newsreader)
>> _______________________________________
>> function ct_complex_add(a, b) {
>> var n = Math.min(a.length, b.length);
>>
>> var sum = new Array(n);
>>
>> for (var i = 0; i < n; ++i) {
>> sum[i] = a[i] + b[i];
>> }
>>
>> return sum;
>> }
>> _______________________________________
>>
>>
>> You can call it like:
>> _______________________________________
>> {
>> var r = ct_complex_add([1, 2], [3, 4]);
>> alert("r:(" + r + ")");
>> return true;
>> }
>> _______________________________________
>>
>>
>> We can add extra elements to the arrays, and the function
>> (ct_complex_add) still works:
>>
>> _______________________________________
>> {
>>
>> var r = ct_complex_add([1, 2, 3, 4], [5, 6, 7, 8]);
>> alert("r:(" + r + ")");
>> return true;
>> }
>> _______________________________________
>>
>>
>>
>>
>> We can add extra elements or even pass arrays that have different number
>> of elements:
>> _______________________________________
>> {
>>
>> var r = ct_complex_add([1, 2, 3], [4, 5, 6, 7]);
>> alert("r:(" + r + ")");
>> return true;
>> }
>> _______________________________________
>>
>>
>>
>> What do you think of this? Is it a bit too contrived?
>
> What do the arrays represent in this case? Before it was [Re,Im]
>
x, y, z, w? I admit this is highly contrived wrt justifying arrays via
looping... ;^o
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2016-06-25 18:24 -0700 |
| Message-ID | <fd54b793-af20-4c86-8c64-064fdba4bd24@googlegroups.com> |
| In reply to | #30755 |
On Saturday, June 25, 2016 at 8:03:15 PM UTC-5, Chris M. Thomasson wrote: > On 6/24/2016 7:16 AM, Michael Haufe (TNO) wrote: > >> What do you think of this? Is it a bit too contrived? > > > > What do the arrays represent in this case? Before it was [Re,Im] > > > > x, y, z, w? I admit this is highly contrived wrt justifying arrays via > looping... ;^o You can represent Complex Numbers as Matrices as well if you want. It's been 2 years or so since I did much Linear Algebra, so I'd have to brush up again on the subject to provide any insight if you go in that direction though. Basically given two Matrices: // 2x2 Identity matrix var I = [ 1, 0, 0, 1 ] // J**2 == -I // eigenvalues(J) == [i, -i] where i = sqrt(-1) var J = [ 0, -1, 1, 0 ] You can represent the complex number a + bi instead as the matrix aI + bJ and get all the benefits of matrix operations. I would still suggest having an object to represent these of course. [*] <https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors>
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-07-01 13:52 -0700 |
| Message-ID | <nl6l6u$k7j$1@dont-email.me> |
| In reply to | #30756 |
On 6/25/2016 6:24 PM, Michael Haufe (TNO) wrote: > On Saturday, June 25, 2016 at 8:03:15 PM UTC-5, Chris M. Thomasson wrote: >> On 6/24/2016 7:16 AM, Michael Haufe (TNO) wrote: > >>>> What do you think of this? Is it a bit too contrived? >>> >>> What do the arrays represent in this case? Before it was [Re,Im] >>> >> >> x, y, z, w? I admit this is highly contrived wrt justifying arrays via >> looping... ;^o > > You can represent Complex Numbers as Matrices as well if you want. It's been 2 years or so since I did much Linear Algebra, so I'd have to brush up again on the subject to provide any insight if you go in that direction though. > > Basically given two Matrices: > > // 2x2 Identity matrix > var I = [ > 1, 0, > 0, 1 > ] > > // J**2 == -I > // eigenvalues(J) == [i, -i] where i = sqrt(-1) > var J = [ > 0, -1, > 1, 0 > ] > > You can represent the complex number a + bi instead as the matrix aI + bJ and get all the benefits of matrix operations. I would still suggest having an object to represent these of course. Ah yes. agreed. I think I like the array approach a little better because a user can pass a number like: foo.bar([.1, .2]) instead of: foo.bar(new complex(.1, .2)) This is contrived, but I have always liked arrays wrt storing x, y, z, w, ... like parameters.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web