Joe Riel

9665 Reputation

23 Badges

20 years, 35 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Weird...my browser won't permit copying the Maple code that you entered.  I never had that problem before.

I don't understand why you are specifying a range from 0 to infinity.  The solution is near 0. 

The subsindets procedure can be used here:

isolate(subsindets(eq,integer,``),x);

ImageTools:-View uses maplets to do just that:
 
use ImageTools in View(Checkerboard()) end use;

To seed Maple's random number generator, use the randomize function:

randomize(100):                                      
RandomTools:-Generate(list(integer(range=1..10),10));
                                    [9, 9, 4, 8, 8, 1, 5, 3, 6, 3]

RandomTools:-Generate(list(integer(range=1..10),10));
                                    [3, 3, 2, 1, 9, 5, 1, 10, 7, 3]
# reseed, so result is identical to first call
randomize(100):                                      
RandomTools:-Generate(list(integer(range=1..10),10));
                                    [9, 9, 4, 8, 8, 1, 5, 3, 6, 3]

alias(u = u(x,y)):
 diff(u,x);
                                                 d
                                                 -- u
                                                 dx

diff(u,y);
                                                 d
                                                 -- u
                                                 dy

There is a Bits package:

Bits:-And(12,6);  
                                                   4

You could use patmatch:

ans := 401/2 - 1880/(3*Pi);
patmatch(ans, ab::numeric + cd::numeric/Pi, 's');
                                                       true
(a,b) := (numer,denom)(eval(ab, s));
                                   a, b := 401, 2
(c,d) := (numer,denom)(eval(cd, s));
                                   c, d := -1880, 3

LongestIncreasingSeq := proc(L::list)
local n,G,C;
uses GraphTheory;
    n := nops(L);
    G := Digraph(n
                 , {seq(seq(`if`(L[i]<L[j]
                                 , [i,j]
                                 , NULL
                                )
                            , j = i..n)
                        , i = 1..n-1)}
                );
    C := MaximumClique(G);
    map(op, C, L);
end proc:
Because L is restricted to distinct integers, we can slightly shorten this:
LongestIncreasingSeq := proc(L::list)
local i,j,n;
uses GraphTheory;
    n := nops(L);
    MaximumClique(Digraph(L, {seq(seq(`if`(L[i]<L[j]
                                           , [L[i],L[j]]
                                           , NULL
                                          )
                                      , j = i..n)
                                  , i = 1..n-1)}
                         ));
end proc:

This seems straightforward, that is, no recursion and should be O(n).  I only implemented a test for increasing sequences, but the decreasing one is obvious.  This can be simplified, since it actually returns the sequence and not just the length.

LongestSeq := proc(L :: list(numeric))
local leng,maxlengthth,i,x,xp,endpos;

    if L = [] then return []; end if;
    leng := 1;
    maxlength := 1;
    x := L[1];

    for i from 2 to nops(L) do
        xp := x;
        x := L[i];
        if xp < x then
            leng := leng+1;
        else
            if leng > maxlength then
                maxlength := leng;
                endpos := i-1;
            end if;
            leng := 1;
        end if;
    end do;

    if leng > maxlength then
        maxlength := leng;
        endpos := -1;
    end if;

    L[endpos-maxlength+1..endpos];

end proc:

Just a comment on the code.  Is there a reason you are using both LinearAlgebra and linalg routines?  The latter package is deprecated.

First, you need to precisely define the problem.  Do you want to minimize Int(f-g, 0..1) or Int(abs(f-g), 0..1)?  The latter is considerably more difficult than the former.  Second, just because the derivative is 0 doesn't mean you have a minimum (local or not).

If the absolute value is to be used, then look at the case with m1=0, b1=1/8, m2=1, b2= -1/4.  There are two places where the derivative is 0, both are local minimums, neither corresponds to your proposed solution.

You can take advantage of the Vector constructor and do

for i to 4 do
    e[i] := Vector(4, {i=1});
end do;

Another possibility is to use LinearAlgebra:-UnitVector:

for i to 4 do
   e[i] := LinearAlgebra:-UnitVector(i,4);
end do;

Look at the Statistics package.  To generate a 20x10000 matrix filled with samples of a specific Logistic distribution do, for example

with(Statistics):
X := RandomVariable(Logistic(0.1, 0.5)):
R := Sample(X,[1..20,1..10000]);

Maybe you could give an example of what you want.  Do you have specific values of x in mind?  You could, for example, do

eq := y=x^2+2:
for xx in [1,2,2.3] do
   printf("%f %f\n", xx, eval(rhs(eq),x=xx));
end do:

That only prints the output.  Do you actually want to insert it into a table or Matrix? 

So here's one approach.

restart;
ode1 := diff(y(x),x)^2 + 4*c*diff(y(x),x)+4*c^2*y(x)/(1-x^2);
ics := y(0)=0;
sol := frontend(solve, [ode1, [diff(y(x),x)]], [{`+`,`*`,`^`,list},{}]);
# manually choose one branch
dsol := dsolve(subs(c=3,[sol[1,1],ics]),numeric):
plots[odeplot](dsol,[x,y(x)],0..1);
The other branch is more interesting. Both have a singularity at x=1.
First 98 99 100 101 102 103 104 Last Page 100 of 114