acer

32717 Reputation

29 Badges

20 years, 83 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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

If the expression (dependinng on a, b, and c) has been assigned to the name `expr` then you can create an operator from that with,

f := unapply(expr, [a,b,c]);

 

The assumptions that modify your Int calls -- made using assuming -- don't carry over to the value calls.

Various simplifications can be made on the result of the value or int calls, using the same assumptions, say.

Another possibility is to convert the integrand to expln form prior to using value.

restart

kernelopts(version);

`Maple 2016.2, X86 64 LINUX, Jan 13 2017, Build ID 1194701`

(1)

U1 := `assuming`([Int(ln(r)*sin(k1*Pi*ln(r/Rs)/ln(r4/Rs))/r, r = Rs .. r4)], [Rs > 0, r4 > 0, r4 > Rs, k1::posint])

Int(ln(r)*sin(k1*Pi*ln(r/Rs)/ln(r4/Rs))/r, r = Rs .. r4)

(2)

ans1 := `assuming`([combine(simplify(simplify(combine(evalc(value(U1)))), size))], [Rs > 0, r4 > 0, r4 > Rs, k1::posint])

ln(Rs/r4)*((-1)^k1*ln(r4)+ln(1/Rs))/(k1*Pi)

(3)

`assuming`([value(convert(U1, expln))], [Rs > 0, r4 > 0, r4 > Rs, k1::posint]);

(1/2)*(2*(-1)^(1+k1)*ln(r4)^2*Pi*k1+2*ln(Rs)*ln(r4)*(-1)^k1*Pi*k1+2*ln(Rs)*ln(r4)*Pi*k1-2*ln(Rs)^2*Pi*k1)/(Pi^2*k1^2)

(4)

pars := [Rs = 2, r4 = 1, k1 = 3];

[Rs = 2, r4 = 1, k1 = 3]

 

Int(-ln(r)*sin(3*Pi*ln((1/2)*r)/ln(2))/r, r = 2 .. 1)

 

-0.5097764806e-1

 

-(1/3)*ln(2)^2/Pi

 

-0.5097764806e-1

(5)

U3 := `assuming`([Int(sin(k1*Pi*ln(r/Rs)/ln(r4/Rs))*(r/r4)^(m1*Pi*`τds`/d)/r, r = Rs .. r4)], [Rs > 0, r4 > 0, r4 > Rs, k1::posint, m1::posint, d > 0, `τds` > 0])

Int(sin(k1*Pi*ln(r/Rs)/ln(r4/Rs))*(r/r4)^(m1*Pi*`τds`/d)/r, r = Rs .. r4)

(6)

ans3 := `assuming`([combine(simplify(simplify(combine(evalc(value(U3)))), size))], [Rs > 0, r4 > 0, r4 > Rs, k1::posint, m1::posint, d > 0, `τds` > 0])

d^2*k1*(r4^(m1*Pi*`τds`*ln(Rs^2)/(d*ln(r4/Rs)))*exp(Pi*m1*`τds`*(ln(Rs)^2+ln(r4)^2)/(d*ln(Rs/r4)))-(-1)^k1)*ln(r4/Rs)/(Pi*(ln(Rs)^2*m1^2*`τds`^2+m1^2*`τds`^2*ln(r4)*ln(1/Rs^2)+ln(r4)^2*m1^2*`τds`^2+k1^2*d^2))

(7)

ans3b := `assuming`([numer(ans3)/collect(denom(ans3), m1, proc (u) options operator, arrow; combine(simplify(u, size)) end proc)], [Rs > 0, r4 > 0, r4 > Rs, k1::posint, m1::posint, d > 0, `τds` > 0])

d^2*k1*(r4^(2*m1*Pi*`τds`*ln(Rs)/(d*ln(r4/Rs)))*exp(Pi*m1*`τds`*(ln(Rs)^2+ln(r4)^2)/(d*ln(Rs/r4)))-(-1)^k1)*ln(r4/Rs)/(Pi*`τds`^2*ln(Rs/r4)^2*m1^2+Pi*k1^2*d^2)

(8)

`assuming`([simplify(ans3-ans3b)], [Rs > 0, r4 > 0, r4 > Rs, k1::posint, m1::posint, d > 0, `τds` > 0])

0

(9)

ans3c := `assuming`([simplify(combine(value(simplify(combine(convert(U3, expln))))), size)], [Rs > 0, r4 > 0, r4 > Rs, k1::posint, m1::posint, d > 0, `τds` > 0]):

k1*d^2*ln(Rs/r4)*((-1)^k1-r4^(-m1*Pi*`τds`/d)*Rs^(m1*Pi*`τds`/d))/(Pi*`τds`^2*ln(Rs/r4)^2*m1^2+Pi*k1^2*d^2)

(10)

parsmore := [Rs = 2, r4 = 1, k1 = 3, m1 = 2, d = 1/3, `τds` = 1/4];

-1.786983542

(11)

``

Download integrals_acc.mw

Try this in your Maple 2016, using the name `#msub(mi("n"),mi("r"))` wrapped in a typeset call.

mprime_ac.mw

If you are in (plaintext) 1D Maple Notation mode then you can do it as below.

If you are in 2D Input mode then you can use the Accent palette to insert a typeset c with a circumflex accent. See below for a result.

plot( sin(x), x = 0 .. Pi, size = [600,200],
      labels = [ `#mover(mi("c"),mo("ˆ"))`, y ],
      tickmarks = [[], []], gridlines = false );

plot(sin(x), x = 0 .. Pi, size = [600, 200], labels = [`#mover(mi("c"),mo("ˆ"))`, y], tickmarks = [[], []], gridlines = false)

``

Download accent_label.mw

You can plot the four "roots" versus B (for a single value of V), or you can plot a single root versus B (for, say, multiple values of V).

You can use either solve or (a procedure that calls) fsolve, to evaluate the roots for the values of B.

Note the the individual formulas (any of the four returned by solve, whether explicit or as implicit RootOf) do not necessarily correspond to a (perceived) single one of the connected portions of solution curves in the plot of all roots. The same goes for picking off a particular place in the four roots returned by fsolve. Hopefully the colors illustrate this aspect. There are ways in which sometimes one can track one of the curves, say by picking the closest the previous value found, possibly also tracking yhe slope. Root crossing can be problematic. This is generally tricky on mathematical grounds, not just as a Maple issue.

restart;

gm := V -> 1/sqrt(1-V^2):
T := w-k*V:
S := w*V-k:

f := unapply(I*B*gm(V)^3*T^3+gm(V)^2*T^2
             -I*gm(V)^3*T*S^2-1/3*I*B*gm(V)^3*S^3*T-1/3*gm(V)^2*S^2,
             w,B,V,k):

k:=2:
Vlist:=[1/2, 2, 4]:

Hgen := simplify(rationalize(f(w,B,V,k)));

2*(-V^2+1)^(1/2)*(((-(1/2)*w^2+6)*V^2-4*w*V+(3/2)*w^2-2)*(-V^2+1)^(1/2)+I*(B*w^3*V^3+((-6*B+3)*w^2-12*B)*V^2+(24*B-12)*w*V-3*B*w^2-8*B+12)*(V-(1/2)*w))/(3*V^4-6*V^2+3)

H := simplify(eval(Hgen, V=Vlist[1]));

-(1/27)*3^(1/2)*((-11*w^2+16*w+4)*3^(1/2)+I*(B*w^3+(-36*B+6)*w^2+(96*B-48)*w-88*B+96)*(w-1))

HSols := [solve(numer(H),w,explicit)]:

cols := [red,blue,green,gold]:

H1,H2,H3,H4 := seq(plot([Re,Im](HSols[i]), B=-1.0 .. 1.0,
                        linestyle=[solid, dash], gridlines=false,
                        color=cols[i], title=i),
                   i=1..4):

# plot of multiple roots, for one V value
plots:-display(H1,H2,H3,H4, view=-6..6,
               title=typeset(V=Vlist[1]));

# slower
F:=(B,v,k,i)->fsolve(f(w,B,v,k),w, complex)[i]:
F1,F2,F3,F4 := seq(plot([Re,Im]('F'(B,Vlist[1],k,i)), B=-1.0 .. 1.0,
                        linestyle=[solid, dash], gridlines=false,
                        color=cols[i], title=i),
                   i=1..4):

plots:-display(F1,F2,F3,F4, view=-6..6,
               title=typeset(V=Vlist[1]));

Hgensols := [solve(numer(Hgen),w,explicit)]:
Hgensols := simplify(Hgensols,size) assuming V>0, B::real:

altcols := ["Violet","Orange","Navy"]:

# plot of one root, for multiple V values
plots:-display(
  seq(plot([Re,Im](eval(Hgensols[1], V=Vlist[i])), B=0.0 .. 1.0,
           linestyle=[solid, dash], gridlines=false,
           color=altcols[i], legend=[typeset(V=Vlist[i]), ""]),
      i=1 .. nops(Vlist))
);

 

 

Download rootplot.mw

Just for fun, as it's somewhat obscure and likely not as efficient as the double `seq`. But it's terse, and without dummy names.
restart;
A1:= [a1, a2, a3]:
A2:= [b1, b2]:

map[3](op@zip,`/`,A1,A2);
         
          a1    a2    a3    a1    a2    a3
        [----, ----, ----, ----, ----, ----]
          b1    b1    b1    b2    b2    b2

map[3](op@zip,f,A1,A2);

    [f(a1, b1), f(a2, b1), f(a3, b1), f(a1, b2), f(a2, b2), f(a3, b2)]

Here are three ways it may be accomplished, if I have understood the goal.

odeplots_in_an_Explore_command_ac.mw

(If you feel like some heavier reading you might glance at these two older posts, 1, 2 ).

The result from diff already had the completed square inside the radicals.

with(Typesetting)

Settings(typesetdot = true)

NULL

eq := l = sqrt((d-x(t))^2+h^2)+y(t)

l = ((d-x(t))^2+h^2)^(1/2)+y(t)

a := solve(eq, y(t))

-((d-x(t))^2+h^2)^(1/2)+l

a1 := diff(a, t)

(d-x(t))*(diff(x(t), t))/((d-x(t))^2+h^2)^(1/2)

a2 := diff(a1, t)

(d-x(t))^2*(diff(x(t), t))^2/((d-x(t))^2+h^2)^(3/2)-(diff(x(t), t))^2/((d-x(t))^2+h^2)^(1/2)+(d-x(t))*(diff(diff(x(t), t), t))/((d-x(t))^2+h^2)^(1/2)

collect(a2, diff, proc (u) options operator, arrow; simplify(u, size) end proc)

(d-x(t))*(diff(diff(x(t), t), t))/((d-x(t))^2+h^2)^(1/2)-(diff(x(t), t))^2*h^2/((d-x(t))^2+h^2)^(3/2)

``

Download collect_denominator_ac.mw

Perhaps your would like to use the plots:-logplot command, or the axis options of the plot command.

First 167 168 169 170 171 172 173 Last Page 169 of 340