acer

32587 Reputation

29 Badges

20 years, 35 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The supporting code needs to be auto-execute, for it to work in the MaplePlayer.

The easiest way to do this is put all the supporting code in the Startup Code region (ie. from the main menubar, use Edit->Startup Code).

Cassinian_oval_ac.mw

note: I prefer procedures which utilize uses, rather rely on with being run at the top-level. And I prefer not to declare global variables within a procedure if they don't serve a purpose. Not a big deal. Cassinian_oval_ac2.mw

Either of the two first methods below are about 200 times faster than the last two methods below (MapleMathMatt's and Kitonum's suggestions).

Using inert Int (or int with the numeric option) instead of active int prevents Maple from trying to solve the integral symbolically for each value of epsilon.

Using the operator form of the integrand (or using the specified method) prevents `evalf/int` from trying to check for discontinuities at each value of epsilon.

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

restart;
G := epsilon -> Int( unapply(exp( -epsilon * ( x^4 + x^2 ) ), x), -10 .. 10):
CodeTools:-Usage( plot( G, 0 .. infinity ));

memory used=12.92MiB, alloc change=35.01MiB, cpu time=131.00ms, real time=132.00ms, gc time=6.35ms

restart;
G := Int( exp( -epsilon * ( x^4 + x^2 ) ), x = -10 .. 10, method=_d01ajc):
CodeTools:-Usage( plot( G, epsilon = 0 .. infinity ));

memory used=13.50MiB, alloc change=35.01MiB, cpu time=126.00ms, real time=127.00ms, gc time=5.10ms

restart;
G := proc( epsilon )
  int( exp( -epsilon * ( x^4 + x^2 ) ), x = -10 .. 10, numeric );
end proc:
CodeTools:-Usage( plot( G, 0 .. infinity ));

memory used=3.36GiB, alloc change=36.00MiB, cpu time=26.93s, real time=26.95s, gc time=1.95s

restart;
G := Int( exp( -epsilon * ( x^4 + x^2 ) ), x = -10 .. 10);
CodeTools:-Usage( plot( G, epsilon = 0 .. infinity ));

Int(exp(-epsilon*(x^4+x^2)), x = -10 .. 10)

memory used=3.36GiB, alloc change=36.00MiB, cpu time=27.10s, real time=27.11s, gc time=2.33s

 

Download plot_integral.mw

For this example it seems that fsolve has trouble without some extra hint of the range for some of the variables.

But solve gets it directly.

restart;

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

eqs := {(T[1]-T[0])/(10000-T[1]+T[0]) = -2.000000000,
        (T[2]-T[0])/(20000-T[2]+T[0]) = 0,
        (T[3]-T[0])/(50000-T[3]+T[0]) = 50,
        .1*T[0]+.3*T[1]+.55*T[2]+0.5e-1*T[3]-5000 = 0}:

fsolve(eqs, {T[0], T[1], T[2], T[3]},
       {T[1]=0..20000, T[2]=-infinity..0});

{T[0] = -3450.980392, T[1] = 16549.01961, T[2] = -3450.980392, T[3] = 45568.62745}

solve(eqs);

{T[0] = -3450.980392, T[1] = 16549.01961, T[2] = -3450.980392, T[3] = 45568.62745}

 

Download fsolverng.mw

restart;

L1 := [t-2,(t-2)^2]:        
L2 := [(3*t/2)-4,(3*t/2)-2]:

solve(Equate(L1,L2));

                            {t = 4}

My guess is that you are looking for something like the effect of the plots:-dualaxisplot command.

See this revision: GaußKronrodQuadraturFehlerbehandlung_ac.mw

Don't use the word function like that in relation to Maple. Nobody will know for sure whether you are talking about an expression (which could be evaluated at values for its unknowns) or a procedure (which can be called with values).

I am going to guess that you mean a procedure (of which an arrow-printing operator is one variant).

Have you set up your procedure to do something special (eg, return unevaluated) if it is called with a simple name for its parameter x?

If not, when why not do something like evalf[4](f(x)) where x is some unassigned name?

There is no blazingly simple way to print the body of a procedure and have it be pretty-printed in a modified manner. (There are ways, but advanced.)

restart;

plots:-display(
        seq( plot([cos(t)-q*sin(t), sin(t)+q*cos(t), q=-1..1]),
             t=0..evalf(2*Pi), evalf(Pi/30) ),
        gridlines=false
              );

 

Download some_tangents.mw

And for fun,

Explore(plots:-display(
          seq( plot([cos(n*2*Pi/N)-q*sin(n*2*Pi/N),
                     sin(n*2*Pi/N)+q*cos(n*2*Pi/N), q=-2..2]),
               n=0..N-1 ),
          gridlines=false),
        parameters=[N=1..50], initialvalues=[N=30]);

[edited] The original formulation is not efficient. Each line segments really requires only its two end-points. They are lots of ways to accomplish that: plottools:-line, forced numpoints, pointplot with linestyle, etc. So this runs more smoothly,

Explore(plots:-display(
          seq( plot([seq([cos(n*2*Pi/N)-q*sin(n*2*Pi/N),
                          sin(n*2*Pi/N)+q*cos(n*2*Pi/N)],
                         q=[-2,2])]),
               n=0..N-1 ),
          gridlines=false),
        parameters=[N=1..200], initialvalues=[N=30]);

And, even though the earlier code wasn't unbearably slow,

plots:-display(
          seq( plot([seq([cos(n*2*Pi/60)-q*sin(n*2*Pi/60),
                          sin(n*2*Pi/60)+q*cos(n*2*Pi/60)],
                         q=[-2,2])]),
               n=0..60 ),
          gridlines=false);

or (better than the original, but not as quick as that immediately above),

plots:-display(
        seq( plot([cos(t)-q*sin(t), sin(t)+q*cos(t), q=-2..2],
                  adaptive=false, numpoints=2),
             t=0..evalf(2*Pi), evalf(Pi/30) ),
        gridlines=false
              );

The eigenvectors associated with eigenvalue evals[i] can be computed as the Null Space of the Characteristic Matrix using at lambda = evals[i] .

restart;

XCov:=Matrix([[4048/5, -817/5, -122/5], [-817/5, 921/10, -1999/10], [-122/5, -1999/10, 8341/10]]);

Matrix(3, 3, {(1, 1) = 4048/5, (1, 2) = -817/5, (1, 3) = -122/5, (2, 1) = -817/5, (2, 2) = 921/10, (2, 3) = -1999/10, (3, 1) = -122/5, (3, 2) = -1999/10, (3, 3) = 8341/10})

with(LinearAlgebra):

det := Determinant(XCov-lambda*IdentityMatrix(3));

11846839/2-(3797086/5)*lambda+(8679/5)*lambda^2-lambda^3

evals := Vector([solve(det=0.0, lambda)]);

Vector(3, {(1) = 7.943520930, (2) = 837.8501420, (3) = 890.0063371})

CharacteristicMatrix(XCov, lambda);

Matrix(3, 3, {(1, 1) = lambda-4048/5, (1, 2) = 817/5, (1, 3) = 122/5, (2, 1) = 817/5, (2, 2) = lambda-921/10, (2, 3) = 1999/10, (3, 1) = 122/5, (3, 2) = 1999/10, (3, 3) = lambda-8341/10})

CharacteristicMatrix(XCov, evals[1]);

Matrix(3, 3, {(1, 1) = -801.6564791, (1, 2) = 817/5, (1, 3) = 122/5, (2, 1) = 817/5, (2, 2) = -84.15647907, (2, 3) = 1999/10, (3, 1) = 122/5, (3, 2) = 1999/10, (3, 3) = -826.1564791})

evecs[1] := NullSpace(CharacteristicMatrix(XCov, evals[1]));

{Vector(3, {(1) = -.20097171043526135, (2) = -.950748499500729, (3) = -.23598233472410096})}

evecs[2] := NullSpace(CharacteristicMatrix(XCov, evals[2]))

{Vector(3, {(1) = -.9265946969725416, (2) = .10633405707523064, (3) = .36071503413121725})}

evecs[3] := NullSpace(CharacteristicMatrix(XCov, evals[3]))

{Vector(3, {(1) = .3178563183964183, (2) = -.29115349733256674, (3) = .9023286551176849})}

# test the first of the eigenvectors corresponding to the third eigenvalue.
# (There's only one such eigenvector, as evecs[3] is a set with just one element.)
XCov . evecs[3][1] - evals[3] . evecs[3][1];

Vector(3, {(1) = -0.7077403552e-8, (2) = 0.6482935078e-8, (3) = -0.2009130640e-7})

seq( seq( Norm( XCov . evecs[i][j] - evals[i] . evecs[i][j] ), j=1..nops(evecs[i])), i=1..3 );

0.643466080418875208e-8, 0.702686975273536518e-8, 0.200913063963525929e-7

# All eigenvectors in a Matrix, as columns
Evecs := `<|>`( seq(seq(evecs[i][j], j=1..nops(evecs[i])), i=1..3 ) );

Matrix(3, 3, {(1, 1) = -.20097171043526135, (1, 2) = -.9265946969725416, (1, 3) = .3178563183964183, (2, 1) = -.950748499500729, (2, 2) = .10633405707523064, (2, 3) = -.29115349733256674, (3, 1) = -.23598233472410096, (3, 2) = .36071503413121725, (3, 3) = .9023286551176849})

# test them all at once
XCov . Evecs - Evecs . DiagonalMatrix(evals);

Matrix(3, 3, {(1, 1) = 0.5480002008e-8, (1, 2) = 0.7026869753e-8, (1, 3) = -0.7077460396e-8, (2, 1) = -0.2597509763e-8, (2, 2) = -0.8063665291e-9, (2, 3) = 0.6482935078e-8, (3, 1) = 0.6434661026e-8, (3, 2) = -0.2735532689e-8, (3, 3) = -0.2009142008e-7})

 

Download eigenvects.mw

There are various ways to simplify your examples. Presumably you want approaches which are understandable and less ad hoc. (In the first examples in this attachment, the evala command does as well as radnormal.)

If the denominators (of the arguments of the ln calls) are factored after expanding, then one of the factors will cancel automatically with part of the corresponding numerator, for your examples. See the last two lines in this attachment, for insight on that as well as expansion without that factoring.

restart;

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

f:=ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2));

ln((1-x)^2*(x+1)^2/((-I*x-I+(-x^2+1)^(1/2))^2*(I*x+I+(-x^2+1)^(1/2))^2))

f2:=ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2));

ln((1-x)^2*(x+1)^2/((-I*x-I+(-x^2+1)^(1/2))^2*(I*x+I+(-x^2+1)^(1/2))^2))^4+2*ln((1-x)^2*(x+1)^2/((-I*x-I+(-x^2+1)^(1/2))^2*(I*x+I+(-x^2+1)^(1/2))^2))^2+ln((1-x)^2*(x+1)^2/((-I*x-I+(-x^2+1)^(1/2))^2*(I*x+I+(-x^2+1)^(1/2))^2))

radnormal(f);

ln((1/4)*(-1+x)^2)

frontend(expand,[radnormal(f2)]);

ln((1/4)*(-1+x)^2)^4+2*ln((1/4)*(-1+x)^2)^2+ln((1/4)*(-1+x)^2)

subsindets(f, specfunc(ln), radnormal);

ln((1/4)*(-1+x)^2)

subsindets(f2, specfunc(ln), radnormal);

ln((1/4)*(-1+x)^2)^4+2*ln((1/4)*(-1+x)^2)^2+ln((1/4)*(-1+x)^2)

subsindets(f2, specfunc(ln), u->ln(numer(op(u))/expand(denom(op(u)))));

ln((-1+x)^2*(x+1)^2/(4*x^2+8*x+4))^4+2*ln((-1+x)^2*(x+1)^2/(4*x^2+8*x+4))^2+ln((-1+x)^2*(x+1)^2/(4*x^2+8*x+4))

subsindets(f2, specfunc(ln), u->ln(numer(op(u))/factor(expand(denom(op(u))))));

ln((1/4)*(-1+x)^2)^4+2*ln((1/4)*(-1+x)^2)^2+ln((1/4)*(-1+x)^2)

 

Download targeted.mw

The procedure Mutate acts in-place on the particleposition Array, so it seems like you want that Array to be a running state of the updated values.

But inside your procedure Mutate there is a statement y :=x .Perhaps you intended y:=copy(x), and to have the last line of that procedure be return y ?

If L2 is very large then you might want to ascertain a true result as soon as any element of L2 is found to be in the union of the L1 sets.

In other words, you may find it too costly to compute a full set intersection (or minus) involving examining all of L2, or a full seq of tests over all of L2.

In such a case you could try ormap , which will return true as soon as it finds its first true result. Ie.

   ormap(member,L2,`union`(L1[]));

There may, however, be some function-call overhead for calling member many times. (There are some kinds of calculation where it matters whether you want to focus on worst possible vs best average behavior, etc, in which case deciding what's best can entail figuring out what's likely as well as what you want.)
 

That do is our of place. That keyword is not part of an if..then..end if.

You likely don't want a loop here.

Are you trying to get something like this?

Here I use to frontend to suppress/freeze the derivatives, while using eliminate on the variable m, and then consider the remaining conditions (implied equations, the second part of what eliminate returns).

restart;

eq1 := -T*sin(theta(t)) = m*(diff(X(t), t, t)
       +L*(diff(theta(t), t, t))*cos(theta(t))
       -L*(diff(theta(t), t))^2*sin(theta(t))):

eq2 := T*cos(theta(t))-m*g = m*(diff(Y(t), t, t)
       +L*(diff(theta(t), t, t))*sin(theta(t))
       +L*(diff(theta(t), t))^2*cos(theta(t))):

K := frontend(eliminate,[{eq1,eq2},{m}],[{`+`,`*`,`=`,set},{}]):

conds := simplify(map(`=`,K[2],0));

{T*(L*(diff(diff(theta(t), t), t))+(diff(diff(X(t), t), t))*cos(theta(t))+sin(theta(t))*(diff(diff(Y(t), t), t)+g)) = 0}

(1)

conds[1]/T;

L*(diff(diff(theta(t), t), t))+(diff(diff(X(t), t), t))*cos(theta(t))+sin(theta(t))*(diff(diff(Y(t), t), t)+g) = 0

(2)

 

Download eliminate_examp.mw

You can substitute for m+F(xi) using freeze and algsubs, and then collect, and then resubstitute using thaw.

You have a variety of ways to simplify, or not, the coefficients (of the m+F(xi) powers). Below I show two ways, one with some simplification.

restart;

T := K+F(xi)*F(xi):

U := alpha[0]+alpha[1]*(m+F(xi))+beta[1]/(m+F(xi))
    +alpha[2]*(m+F(xi))*(m+F(xi))+beta[2]/(m+F(xi))^2:

d := alpha[1]*T-beta[1]*T/(m+F(xi))^2+2*alpha[2]*(m+F(xi))*T
     -2*beta[2]*T/(m+F(xi))^3:

S := (2*alpha[1]*F(xi)-2*beta[1]*F(xi)/(m+F(xi))^2
     +2*beta[1]*(K+F(xi)^2)/(m+F(xi))^3
     +2*alpha[2]*(K+F(xi)^2)+4*alpha[2]*(m+F(xi))*F(xi)
     -4*beta[2]*F(xi)/(m+F(xi))^3
     +6*beta[2]*(K+F(xi)^2)/(m+F(xi))^4)*T:

expand((2*w*k*k)*beta*S-(2*A*k*k)*d-2*w*U+k*U*U):

value(%):

expr := simplify(%):

temp := algsubs(m+F(xi)=freeze(m+F(xi)),numer(expr)):

thaw(collect(temp, freeze(m+F(xi)))/denom(expr));

(k*alpha[2]^2*(m+F(xi))^8+2*k*alpha[1]*alpha[2]*(m+F(xi))^7+(m+F(xi))^6*(2*k*alpha[0]*alpha[2]+k*alpha[1]^2-2*w*alpha[2])+(8*F(xi)^3*beta*k^2*w*alpha[2]+8*K*F(xi)*beta*k^2*w*alpha[2]-4*A*F(xi)^2*k^2*alpha[2]-4*A*K*k^2*alpha[2]+2*k*alpha[0]*alpha[1]+2*k*alpha[2]*beta[1]-2*w*alpha[1])*(m+F(xi))^5+(-2*A*k^2*alpha[1]*K+4*w*k^2*beta*alpha[2]*F(xi)^4+4*w*k^2*beta*alpha[1]*F(xi)^3+(8*K*beta*k^2*w*alpha[2]-2*A*k^2*alpha[1])*F(xi)^2+4*w*k^2*beta*alpha[1]*F(xi)*K+k*alpha[0]^2-2*w*alpha[0]+4*w*k^2*beta*alpha[2]*K^2+2*k*alpha[1]*beta[1]+2*k*alpha[2]*beta[2])*(m+F(xi))^4+(2*k*alpha[0]*beta[1]+2*k*alpha[1]*beta[2]-2*w*beta[1])*(m+F(xi))^3+(-4*w*k^2*beta*beta[1]*F(xi)^3-4*w*k^2*beta*beta[1]*F(xi)*K+2*A*k^2*beta[1]*F(xi)^2+2*A*k^2*beta[1]*K+2*k*alpha[0]*beta[2]+k*beta[1]^2-2*w*beta[2])*(m+F(xi))^2+(4*w*k^2*beta*beta[1]*F(xi)^4-8*w*k^2*beta*beta[2]*F(xi)^3+(8*K*beta*k^2*w*beta[1]+4*A*k^2*beta[2])*F(xi)^2-8*w*k^2*beta*beta[2]*F(xi)*K+4*w*k^2*beta*beta[1]*K^2+2*k*beta[1]*beta[2]+4*A*k^2*beta[2]*K)*(m+F(xi))+12*w*k^2*beta*beta[2]*F(xi)^4+24*w*k^2*beta*beta[2]*K*F(xi)^2+12*w*k^2*beta*beta[2]*K^2+k*beta[2]^2)/(m+F(xi))^4

simplify(% - expr);

0

Numer:=collect(temp, freeze(m+F(xi)),
               uu->collect(uu,[beta,beta[1],beta[2],k,A,w],
                           uuu->factor(uuu))):

new := thaw(Numer/denom(expr));

(k*alpha[2]^2*(m+F(xi))^8+2*k*alpha[1]*alpha[2]*(m+F(xi))^7+((2*alpha[0]*alpha[2]+alpha[1]^2)*k-2*alpha[2]*w)*(m+F(xi))^6+(8*F(xi)*alpha[2]*(K+F(xi)^2)*w*k^2*beta+2*k*alpha[2]*beta[1]-4*alpha[2]*(K+F(xi)^2)*A*k^2+2*k*alpha[0]*alpha[1]-2*w*alpha[1])*(m+F(xi))^5+(4*(K+F(xi)^2)*(F(xi)^2*alpha[2]+K*alpha[2]+alpha[1]*F(xi))*w*k^2*beta+2*k*alpha[1]*beta[1]+2*k*alpha[2]*beta[2]-2*alpha[1]*(K+F(xi)^2)*A*k^2+k*alpha[0]^2-2*w*alpha[0])*(m+F(xi))^4+((2*k*alpha[0]-2*w)*beta[1]+2*k*alpha[1]*beta[2])*(m+F(xi))^3+(-4*F(xi)*(K+F(xi)^2)*w*k^2*beta[1]*beta+k*beta[1]^2+(2*F(xi)^2+2*K)*A*k^2*beta[1]+(2*k*alpha[0]-2*w)*beta[2])*(m+F(xi))^2+((4*(K+F(xi)^2)^2*w*k^2*beta[1]-8*F(xi)*(K+F(xi)^2)*w*k^2*beta[2])*beta+2*k*beta[1]*beta[2]+(4*F(xi)^2+4*K)*A*k^2*beta[2])*(m+F(xi))+12*(K+F(xi)^2)^2*w*k^2*beta[2]*beta+k*beta[2]^2)/(m+F(xi))^4

simplify(expr - new);

0

 

Download collect_freeze.mw

I don't know of a way to accomplish what you want using a legend per se, especially if the font size and dimensions have to be as you have them.

But what about a combination of shorter line segments alongside textplot, inlined into the plot? It's more effort to set up just right, but gives more flexibility to correct for the linestyles. legendwidth.mw

First 165 166 167 168 169 170 171 Last Page 167 of 338