acer

32822 Reputation

29 Badges

20 years, 131 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

The help-page ?Fit says that the second argument, "X", should be the independent data. For several independent variables, that data should be in a Matrix.

As you had it originally, the x, y, and z data were all being supplied as separate arguments. So Maple was trying to interpret the z array as the fourth parameter which is supposed to be designate the names of the independent variables.

The solution is to combine x and y into that single Matrix of independent data. See my response above.

Double check that it is oriented correctly, with x and y as the two columns of the 48x2 Matrix. You mentioned that x and y were "arrays". How they may be joined, to make a single Matrix with x and y as the two columns, will differ according to whether x and y are lists, arrays, or Vectors. For example,

> x:=[a,b]: y:=[c,d]:
> Matrix([x,y])^%T;
                                   [a    c]
                                   [      ]
                                   [b    d]
 
> x:=array(1..2,[a,b]): y:=array(1..2,[c,d]):
> Matrix([[x],[y]])^%T;
                                   [a    c]
                                   [      ]
                                   [b    d]
 
> x:=Vector([a,b]): y:=Vector([c,d]):
> Matrix([x,y]);
                                   [a    c]
                                   [      ]
                                   [b    d]

acer

The help-page ?Fit says that the second argument, "X", should be the independent data. For several independent variables, that data should be in a Matrix.

As you had it originally, the x, y, and z data were all being supplied as separate arguments. So Maple was trying to interpret the z array as the fourth parameter which is supposed to be designate the names of the independent variables.

The solution is to combine x and y into that single Matrix of independent data. See my response above.

Double check that it is oriented correctly, with x and y as the two columns of the 48x2 Matrix. You mentioned that x and y were "arrays". How they may be joined, to make a single Matrix with x and y as the two columns, will differ according to whether x and y are lists, arrays, or Vectors. For example,

> x:=[a,b]: y:=[c,d]:
> Matrix([x,y])^%T;
                                   [a    c]
                                   [      ]
                                   [b    d]
 
> x:=array(1..2,[a,b]): y:=array(1..2,[c,d]):
> Matrix([[x],[y]])^%T;
                                   [a    c]
                                   [      ]
                                   [b    d]
 
> x:=Vector([a,b]): y:=Vector([c,d]):
> Matrix([x,y]);
                                   [a    c]
                                   [      ]
                                   [b    d]

acer

Sorry, I answered this out of order.

acer

Sorry, I answered this out of order.

acer

It's not a great improvement, as it just produces a piecewise of a comparison of piecewises. One could get similar behaviour with the more straightforward (original) application of `min` and the introduction of `unapply`. Ie,

> f1:=x->piecewise(x>0,cos(x),1);
                    f1 := x -> piecewise(0 < x, cos(x), 1)

> f2:=x->piecewise(x>0,sin(x),-1);
                    f2 := x -> piecewise(0 < x, sin(x), -1)

> f3:=unapply(min(f1(x),f2(x)),x);

   f3 := x -> min(piecewise(0 < x, cos(x), 1), piecewise(0 < x, sin(x), -1))
 
> f3(2);
                                    cos(2)

That seems just as easy as does the following, given that one started with a request about using `min`.

> f3:=unapply(piecewise(f1(x)<f2(x),f1(x),f2(x)),x);

f3 := x -> piecewise(
 
    piecewise(0 < x, cos(x), 1) < piecewise(0 < x, sin(x), -1),
 
    piecewise(0 < x, cos(x), 1), piecewise(0 < x, sin(x), -1))

> f3(2);
                                    cos(2)

The original poster might be satisfied with using `unapply` on the `min` call, without even any combining of piecewises at all.  Simply using `unapply` alone might serve all his needs.

What I am now wondering is whether one can get Maple to actually combine this slightly harder example (with sin and cos) into a single piecewise. Such a simplified result would evaluate faster, or be simpler to subsequently manipulate. Neither `combine`, `simplify`, or the undocumented PiecewiseTools:-Simplify managed it, for my example.

The combined, single piecewise would look like this,
> f4 := unapply(piecewise(x>0,min(sin(x),cos(x)),-1),x);

             f4 := x -> piecewise(0 < x, min(cos(x), sin(x)), -1)

acer

It also helps if the specific tasks in the "use cases" are not all chosen purely according to what the product creators can imagine. Having a really good mechanism by which users and potential users can provide input into the set of tasks is important.

acer

That example also worked out using `simplify` instead of `combine`.

But what about this one?

f1:=x->piecewise(x>0,cos(x),1);

f2:=x->piecewise(x>0,sin(x),1);

acer

The number of views of a blog posting used to be shown here, beside the entry.

After a year or so of mapleprimes (the long "beta"?) that functionality was removed. I once posted about that, and the response (by Will? I can't find it now) was that someone would look into it.

acer

`add` is faster than `sum` for this sort of thing. It was about 2.5 times faster to compute p(2000) using `add` rather than `sum`, for example.

Writing a truly recursive procedure `s`, with option remember, is also faster than the above `sum` code (but not as fast as with `add`). But it could help, if you intend on computing some sorts of very long sets of increasing values with it.

s := proc(n)
local k;
option remember;
    if n = 1 or n = 2 then return 1
    else for k from 2 to n do
            s(k) := 2*add(s(i)*s(k - i), i = 1 .. k - 2) + s(k - 1)
        end do
    end if;
    s(n)
end proc:

So, once s(2000) is computed then s(1000) is computed near instantaneously, as it only requires a remember-table lookup.

I didn't bother considering whether there is any closed form of any of this.

acer

`add` is faster than `sum` for this sort of thing. It was about 2.5 times faster to compute p(2000) using `add` rather than `sum`, for example.

Writing a truly recursive procedure `s`, with option remember, is also faster than the above `sum` code (but not as fast as with `add`). But it could help, if you intend on computing some sorts of very long sets of increasing values with it.

s := proc(n)
local k;
option remember;
    if n = 1 or n = 2 then return 1
    else for k from 2 to n do
            s(k) := 2*add(s(i)*s(k - i), i = 1 .. k - 2) + s(k - 1)
        end do
    end if;
    s(n)
end proc:

So, once s(2000) is computed then s(1000) is computed near instantaneously, as it only requires a remember-table lookup.

I didn't bother considering whether there is any closed form of any of this.

acer

Do you mean this one, attributed to Ramanujan? (Using natural logarithm, so adjusted by factor of ln(10.)).

> ff := n*ln(n) - n + ln(n*(1+4*n*(1+2*n)))/6 + ln(Pi)/2;

        ff := n ln(n) - n + 1/6 ln(n (1 + 4 n (1 + 2 n))) + 1/2 ln(Pi)

> evalf[30](evalf[5000](eval(ff,n=3000)/ln(10.)));
                        9130.61798107450627025514189604

> evalf[30](ln(evalf[5000](3000!))/ln(10.));
                        9130.61798107450628141828801479

> evalf[30](evalf[5000](eval(ff,n=2^32)/ln(10.)));
                                                        11
                     0.395079669763461126642613649132 10

> trunc(%);
                                  39507966976

So, the above is indicating 39507966976 decimal digits in (2^32)!.

acer

Do you mean this one, attributed to Ramanujan? (Using natural logarithm, so adjusted by factor of ln(10.)).

> ff := n*ln(n) - n + ln(n*(1+4*n*(1+2*n)))/6 + ln(Pi)/2;

        ff := n ln(n) - n + 1/6 ln(n (1 + 4 n (1 + 2 n))) + 1/2 ln(Pi)

> evalf[30](evalf[5000](eval(ff,n=3000)/ln(10.)));
                        9130.61798107450627025514189604

> evalf[30](ln(evalf[5000](3000!))/ln(10.));
                        9130.61798107450628141828801479

> evalf[30](evalf[5000](eval(ff,n=2^32)/ln(10.)));
                                                        11
                     0.395079669763461126642613649132 10

> trunc(%);
                                  39507966976

So, the above is indicating 39507966976 decimal digits in (2^32)!.

acer

I see. The problem is that this is a number so large that attempting to compute it in the most obvious way -- by raising Maple's working precision -- may well fail. In such situations, there may be transformations which allow one to ascertain some quantitative properties of the number.

Are you looking for the leading digits of the floating-point representation of this number?

1/ln(2)*ln(GAMMA(4294967297));

If so, then how many digits would you need to find?

Or would knowing the exponent, in base 10, suffice?

(That question can be modified analogously, for numbers large enough, to "how many digits of the exponent would you need, or would the exponent of the exponent suffice? And so on.)

acer

I see. The problem is that this is a number so large that attempting to compute it in the most obvious way -- by raising Maple's working precision -- may well fail. In such situations, there may be transformations which allow one to ascertain some quantitative properties of the number.

Are you looking for the leading digits of the floating-point representation of this number?

1/ln(2)*ln(GAMMA(4294967297));

If so, then how many digits would you need to find?

Or would knowing the exponent, in base 10, suffice?

(That question can be modified analogously, for numbers large enough, to "how many digits of the exponent would you need, or would the exponent of the exponent suffice? And so on.)

acer

I think that the idea is to run just one of those. The first (export) is for Bourne shell (or its relatives like bash and zsh) while the second (setenv) is for C shell (or tcsh).

If the first worked for you, then you shouldn't need to run the second.

acer

First 533 534 535 536 537 538 539 Last Page 535 of 601