Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

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

Social Networks and Content at Maplesoft.com

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 answers submitted by Alec Mihailovs

In this example, that can be done as

f:=1/2*x*(1-x) - (y1+y2)*x;

                          x (1 - x)
                     f := --------- - (y1 + y2) x
                              2

d1:=implicitdiff(f,x,y1);

                                     2 x
                    d1 := - ----------------------
                            -1 + 2 x + 2 y1 + 2 y2

g1 := y1 *x - 1/2*y1;

                         g1 := y1 x - 1/2 y1

s1:=solve(diff(g1,y1)+diff(g1,x)*d1,{y1});

                                   2
             s1 := {y1 = -2 x + 2 x  + 2 x y2 + 1/2 - y2}

f1:=eval(f,s1);

                 x (1 - x)              2
           f1 := --------- - (-2 x + 2 x  + 2 x y2 + 1/2) x
                     2

d2:=implicitdiff(f1,x,y2);

                                     2 x
                       d2 := - ---------------
                               -3 + 6 x + 4 y2

g2:= y2*x - 1/2*y2;

                         g2 := x y2 - 1/2 y2

s2:=solve(diff(g2,y2)+diff(g2,x)*d2,{y2});

                                             2
                                3 (-4 x + 4 x  + 1)
                  s2 := {y2 = - -------------------}
                                    4 (-1 + x)

f2:=eval(f1,s2);

                     /                             2           \
         x (1 - x)   |          2   3 x (-4 x + 4 x  + 1)      |
   f2 := --------- - |-2 x + 2 x  - --------------------- + 1/2| x
             2       \                   2 (-1 + x)            /

sol:={solve(f2,{x})};

                     sol := {{x = 0}, {x = 5/8}}

sol1:=map(e->e union eval(s2,e),sol);

           sol1 := {{x = 0, y2 = 3/4}, {x = 5/8, y2 = 1/8}}

sol2:=map(e->e union eval(s1,e),sol1);

  sol2 := {

        {x = 0, y1 = -1/4, y2 = 3/4}, {x = 5/8, y1 = 1/16, y2 = 1/8}}

Alec

Here is a comparison of the algorithm that I suggested, with LSSolve.

A:=LinearAlgebra:-RandomMatrix(14,4);

                         [ 14 x 4 Matrix        ]
                    A := [ Data Type: anything  ]
                         [ Storage: rectangular ]
                         [ Order: Fortran_order ]

b:=LinearAlgebra:-RandomVector(14);

                       [ 14 Element Column Vector ]
                  b := [ Data Type: anything      ]
                       [ Storage: rectangular     ]
                       [ Order: Fortran_order     ]

LinearAlgebra:-LeastSquares(A,b);

                        [ 5717212709265904  ]
                        [------------------ ]
                        [232971854192661757 ]
                        [                   ]
                        [1041432067870035917]
                        [-------------------]
                        [2329718541926617570]
                        [                   ]
                        [ 58679259776061227 ]
                        [-------------------]
                        [2329718541926617570]
                        [                   ]
                        [-132104951888408025]
                        [-------------------]
                        [232971854192661757 ]

evalf(%);

                           [0.02454035801]
                           [             ]
                           [0.4470205517 ]
                           [             ]
                           [0.02518727422]
                           [             ]
                           [-0.5670425397]

A1:=A[..,[1..3]];

                          [ 14 x 3 Matrix        ]
                    A1 := [ Data Type: anything  ]
                          [ Storage: rectangular ]
                          [ Order: Fortran_order ]

LinearAlgebra:-LeastSquares(A1,b);

                           [ 97988065792  ]
                           [------------- ]
                           [1818989788461 ]
                           [              ]
                           [ 28167864493  ]
                           [ ------------ ]
                           [ 209079286030 ]
                           [              ]
                           [ 728848729021 ]
                           [--------------]
                           [18189897884610]

evalf(%);

                           [0.05386949746]
                           [             ]
                           [0.1347233627 ]
                           [             ]
                           [0.04006887414]

Optimization[LSSolve](
    [seq(A[i,1]*s1 + A[i,2]*s2 + A[i,3]*s3 + A[i,4]*s4 - b[i],
    i = 1 .. 14)], 
    s1 = 0 .. 1, s2 = 0 .. 1, s3 = 0 .. 1, s4 = 0 .. 1);

  [17045.1786572287201, [s1 = 0.0538694974615032686,

        s2 = 0.134723362738852548, s3 = 0.0400688741434693796,

        s4 = 0.]]

The results look the same.

Alec

The first step can be done using implicitdiff,

f := x^2 + y1/y2:

d1:=implicitdiff(f,x,y1);

                                      1
                            d1 := - ------
                                    2 x y2

d2:=implicitdiff(f,x,y2);

                                    y1
                            d2 := -------
                                        2
                                  2 x y2

Now, steps 2 and 3 could be done as

g1:=x*y1;

                              g1 := x y1

y1:=solve(diff(g1,y1)+diff(g1,x)*d1,y1);

                                     2
                            y1 := 2 x  y2

g2:=x+y2;

                             g2 := x + y2

y2:=solve(diff(g2,y2)+diff(g2,x)*d2,y2);

                               y2 := -x

A problem with that in this example is that

y1;

                                    3
                                -2 x

f;

                                    2
                                 3 x

and f=0 gives x=0, then y1=0 and y2=0, and we can't plug that in the original expression for f because of division by 0. So in this example there are no solutions.

Alec

I would use LinearAlgebra:-LeastSquares and then replace the coordinates that are out of ranges with closest end of the range values. For example, if the range is 5..500 and the solution is 1000, it would be 500, and if the solution is -100, it would be 5.

That should give the same answer as using Optimization package. It looks longer than with Optimization package, but the benefit is that it avoids Optimization package bugs.

Alec

Assuming that your function is f(phi,theta) and not f(r,theta) (because r is constant on a sphere), that can be done as

plots:-complexplot3d([1,f], 0..2*Pi, 0..Pi,
    style=patchnogrid, 
    coords=spherical, 
    scaling=constrained);

or

plots:-complexplot3d([1,f(phi,theta)], 
    phi=0..2*Pi, theta=0..Pi, 
    style=patchnogrid, 
    coords=spherical, 
    scaling=constrained);

For example,

plots:-complexplot3d([1, cos(theta)-sin(phi)], 
    phi = 0 .. 2*Pi, theta = 0 .. Pi, 
    style = patchnogrid, 
    coords = spherical, 
    scaling = constrained);

135_sphere.jpg

One can also directly transform the densityplot. In this example,

plottools:-transform((phi,theta)->
    [sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta)])(
    plots:-densityplot(cos(theta)-sin(phi), 
        phi = 0 .. 2*Pi, theta = 0 .. Pi, 
        style = patchnogrid, colorstyle=HUE));

Alec

a:=9:
error "Value %1 has been entered for  parameter a
    is not valid", a;
Error, Value 9 has been entered for  parameter a 
    is not valid

Alec

display( c1,
    pieslice([0,0],10,0..5*Pi/9,color=blue),
    axes=none);

135_pieslice.gif

You could add c2 to the display command if desirable, as well as 0 and 10 using textplot.

You can upload a file through My files in the Navigation menu at the left hand side and provide a link to it in your post.

Alec

Pros can canculate anything,

E:=map(diff,B,t);
map(x->frontend(diff,[x,diff(q[1](t),t)]),E);

Hope that this assistantion was helpful.

Alec

The difference between init and ModuleLoad is that ModuleLoad is executed when the module is loaded first time in the session, even if it is loaded by executing m:-f and not as with(m), and init is not executed if the module export is called, but only after with(Foo). Here is the demonstration,

LibraryTools:-Create("foom.mla");
libname:=".",libname:
Foo:=module()
    export init,f;
    option package;
    init:=proc()
        print(`You are proud user of the Foo-package`)
    end;
    f:=1;
end:

m := module() option package; 
    export f;
    local ModuleLoad;
    ModuleLoad:=proc() 
        print("You are proud user of the Foo-package!")
    end;
    f:=1;
end:

savelib(Foo,m);
restart;
libname:=".",libname:

Foo:-f(3);

                                  1
with(Foo);
                You are proud user of the Foo-package

                              [f, init]

m:-f(3);
               "You are proud user of the Foo-package!"


                                  1
with(m);

                                 [f]

Alec

You could include that in init. Something like

Foo:=module()
    export init;
    option package;
    init:=proc()
        print(`You are proud user of the Foo-package`);
    end
end:

with(Foo);

                You are proud user of the Foo-package

                                [init]

Alec

You could try print. For example,

to 2 do to 2 do plot(1) od od;

doesn't produce plots with the default printlevel setting, but

to 2 do to 2 do print(plot(1)) od od;

produces 4 plots.

Another solution is to increase printlevel. The former example would show plots after setting

printlevel:=2;

But that might have some negative effects (printing more than you would normally want.)

Alec

The captions option seems to be broken in BoxPlot. At least I couldn't make it working, and the help page doesn't have an example with it.

Alec

You could do that with Statistics instead of stats,

with(Statistics):

data := [3, 6, 6, 10, 12, 12, 12, 12, 12, 13, 
     13, 15, 15, 15, 16, 16, 16, 17, 17, 20, 20]:

FivePointSummary(data);

  [minimum = 3., lowerhinge = 12., median = 13., upperhinge = 16.,

        maximum = 20.]

BoxPlot(data);

To use the BoxPlot with just 5 point summaries, one can duplicate the hinges,

data1 := [3, 12, 12, 13, 16, 16, 20]: 

data2 := [4, 9, 9, 12, 18, 18, 19]:

BoxPlot([data1,data2],deciles=false,mean=false);

135_boxplot.gif

Alec

If you are in Windows, you could do that in Maple Calculator (which you can find in the Maple 13 group in the Start menu). Click Settings there and switch from Radians to Degrees.

In Maple, it is not a good idea to use degrees instead of radians, because many formulas, for derivatives and integrals, for instance, look different in degrees than in radians. If you don't need such things, then Maple calculator should be good enough for your purposes.

Alec

For example,

f:=sin(q[1])*(sin(q[2])*cos(q[3])+cos(q[2])*sin(q[3]));

map(combine,f);

                      sin(q[1]) sin(q[2] + q[3])

or

applyop(combine,2,f);

                      sin(q[1]) sin(q[2] + q[3])

The second question was discussed recently here in a separate thread. In this example, that can be done as

A:=diff(sin(q[1](t)+q[2](t)),t);

                                  //d         \   /d         \\
      A := cos(q[1](t) + q[2](t)) ||-- q[1](t)| + |-- q[2](t)||
                                  \\dt        /   \dt        //

frontend(diff,[A,diff(q[1](t),t)]);

                        cos(q[1](t) + q[2](t))

Alec

First 20 21 22 23 24 25 26 Last Page 22 of 76