Alec Mihailovs

Dr. Aleksandrs Mihailovs

4495 Reputation

21 Badges

20 years, 335 days
Mihailovs, Inc.
Owner, President, and CEO
Tyngsboro, Massachusetts, United States

Social Networks and Content at Maplesoft.com

Maple Application Center

I received my Ph.D. from the University of Pennsylvania in 1998 and I have been teaching since then at SUNY Oneonta for 1 year, at Shepherd University for 5 years, at Tennessee Tech for 2 years, at Lane College for 1 year, and this year I taught at the University of Massachusetts Lowell. My research interests include Representation Theory and Combinatorics.

MaplePrimes Activity


These are replies submitted by Alec Mihailovs

The system of equations DEq and Eq has constant solution f(x)=ug. Here is the description of posting worksheets.
It works in my Windows. By the way, some time ago I posted in MUG detailed instructions how to add missing symbols (such as x-bar or p-hat) to fonts in Windows and Unix.
It works in my Windows. By the way, some time ago I posted in MUG detailed instructions how to add missing symbols (such as x-bar or p-hat) to fonts in Windows and Unix.
The numerical solution can be obtained in exactly the same way,
y0:=y1->rhs(dsolve({diff(y(x),x)=y1*x*y(x),y(1)=y1},numeric)(0)[2]):
y1:=fsolve(sin('y0'(y1))*y1+'y0'(y1)*exp(y1)-2);

                          y1 := 0.9320744122

sol:=dsolve({diff(y(x),x)=y1*x*y(x),y(1)=y1},numeric):
Here is the graph,
plot(x->rhs(sol(x)[2]),-2..2,0..3.5);
The numerical solution can be obtained in exactly the same way,
y0:=y1->rhs(dsolve({diff(y(x),x)=y1*x*y(x),y(1)=y1},numeric)(0)[2]):
y1:=fsolve(sin('y0'(y1))*y1+'y0'(y1)*exp(y1)-2);

                          y1 := 0.9320744122

sol:=dsolve({diff(y(x),x)=y1*x*y(x),y(1)=y1},numeric):
Here is the graph,
plot(x->rhs(sol(x)[2]),-2..2,0..3.5);
Certainly, a lot of further improvements can be done. For instance, even numbers can be eliminated from the very beginning. The following procedure ES2 implements that,
s2 := proc(m::integer[4], km::integer[4], 
A::Array(datatype = integer[4]), 
B::Array(datatype = integer[4]))::integer[4];
   local k, j;
   for k to km do
     if A[k] = 0 then
       for j from (k+1)*(k+k) to m by (2*k+1) do A[j] := 1 end do
     end if
   end do;
   B[1]:=2; j:=2;    
   for k to m do
     if A[k] = 0 then B[j] := 2*k+1; j:=j+1 end if
   end do
end proc:

cs2:=Compiler:-Compile(s2):

ES2 := proc(n)
local A, B, m, km;
    m:=trunc((n-1)/2);
    km:=trunc((sqrt(n)-1)/2);
    A := Array(1 .. m, datatype = integer[4]);
    B := Array(1 .. numtheory:-pi(n), datatype = integer[4]);
    cs2(m, km, A, B);
    B
end proc:
The times look as follows,
time(ES2(10^6));
                                0.078
time(ES1(10^6));
                                0.125
time(ES2(10^7));
                                0.734
time(ES1(10^7));
                                1.358
time(ES2(10^8));
                                8.077
time(ES1(10^8));
                                14.860
A close match is Global Optimization Toolbox - it is not a genetic algorithm optimization tool, but still can be used to explore various engineering system optimization problems.
Here is the procedure ES1 implementing slightly modified version of first suggestion.
s1 := proc(n::integer[4], A::Array(datatype = integer[4]),
B::Array(datatype = integer[4]))::integer[4];
local k, j;
    for k from 2 to isqrt(n) do
        if A[k] = 0 then
            for j from k^2 to n by k do A[j] := 1 end do
        end if
    end do;
    j := 1;
    for k from 2 to n do
        if A[k] = 0 then B[j] := k; j := j + 1 end if
    end do
end proc:

cs1 := Compiler:-Compile(s1):

ES1 := proc(n)
local A, B;
    A := Array(1 .. n, datatype = integer[4]);
    B := Array(1 .. numtheory:-pi(n), datatype = integer[4]);
    cs1(n, A, B);
    B
end proc:
It gives the following time improvements:
time(ES(10^6));
                                0.170
time(ES1(10^6));
                                0.125
time(ES(10^7));  
                                1.703
time(ES1(10^7));
                                1.265
time(ES(10^8));
                                18.265
time(ES1(10^8));
                                14.468
The second suggestion should be corrected, because in stated form s2 produces array B consisting of zeros.
ES is much faster than s5,
time(ES(1000000));
                                0.155
time(sp5(1000000));
                                3.609

is(convert(ES(1000000),set)=sp5(1000000));

                                 true
time(ES(10000000));
                                1.671
time(sp5(10000000));
                               560.231
time(f(10000000));
                               505.578
As one may notice, f is also faster than s5 for large n. Another example,
time(ES(2000000));
                                0.343
time(sp5(2000000));
                                44.312
time(f(2000000));
                                37.156
Even s is faster than s5,
A := Array(1 .. 2000000, datatype = integer[4]):
B := Array(1 .. numtheory:-pi(2000000), datatype = integer[4]):
time(s(2000000,A,B));
                                14.623
ES is much faster than s5,
time(ES(1000000));
                                0.155
time(sp5(1000000));
                                3.609

is(convert(ES(1000000),set)=sp5(1000000));

                                 true
time(ES(10000000));
                                1.671
time(sp5(10000000));
                               560.231
time(f(10000000));
                               505.578
As one may notice, f is also faster than s5 for large n. Another example,
time(ES(2000000));
                                0.343
time(sp5(2000000));
                                44.312
time(f(2000000));
                                37.156
Even s is faster than s5,
A := Array(1 .. 2000000, datatype = integer[4]):
B := Array(1 .. numtheory:-pi(2000000), datatype = integer[4]):
time(s(2000000,A,B));
                                14.623
That's true. It can be corrected by changing the horizontal coordinate accordingly, but that makes some additional work. It may be used if font changing is not desirable.
That's true. It can be corrected by changing the horizontal coordinate accordingly, but that makes some additional work. It may be used if font changing is not desirable.
I should say unless numbers or operations are modified in some way instead of mentioning just numbers :) That is a good idea though. It allows to implement binary arithmetic as follows,
BA:=module() export B,`+`,`-`,`*`,`/`,`^`;
local c;
`+`:=()->:-`+`(args); `-`:=()->:-`-`(args); `*`:=()->:-`*`(args); 
`/`:=()->:-`/`(args); `^`:=()->:-`^`(args);
c:=overload([
proc(a::{float,integer}) option overload; convert(a,binary) end,
proc(a::fraction) option overload; applyop(c,{1,2},a) end,
proc(a::Not(numeric)) option overload; subsindets(a,numeric,c) end]);
B:=(a::uneval)->c(eval(subsindets(a,numeric,x->convert(x,decimal,2)))) end:
Here are some examples,
with(BA):
Digits:=30:
B((10101-10)*11001+100101);
                              1000000000
B(101/110+10011/1101001);
                               1000111
                               -------
                               1000110
B(11^10);
                                 1001
B(evalf(Pi+10));
                   101.001001000011111101101010100
B(combine(sin(10)*cos(10)));
                            1/10 sin(100)
B(110!);
                              1011010000
B(sqrt(10));
                                 (1/10)
                               10
B(sqrt(10.));
                   1.01101010000010011110011001100
B(11.0011^1.101);
                   110.100101000000010001101000111
It still has a glitch with scientific notation,
B(0.1*10^10000);
                                            16
                       0.1000000000000000 10


Ed Pegg wrote an interesting article on Sudoku variations.
By the way, I am not the only one having problems with attaching files. See PS in this post. Perhaps, unlimited quota works as quota = 0?
First 170 171 172 173 174 175 176 Last Page 172 of 180