acer

32822 Reputation

29 Badges

20 years, 133 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@adel-00 Is this what you are trying to accomplish?

Apart from other problems including misuse of assumed names, your sprintf calls tried to use Lambda as if its value were a float, but it is unassigned.

restart:

#assume(theta,real):assume(phi,real):assume(d,real):
#assume(tau,real):
tau0 := 1:

term1:=(exp((1+I*d)*Gamma*tau)*(1-cos(2*Omega1))+cos(2*Omega)*exp((1+I*d)*Gamma*t0)-exp(-(1+I*d)*Gamma*t0))/(2*(1+I*d)):
term2:=-1/2*int(exp((1+I*d)*Gamma*x)*cos(Omega1*(1+erf(tau))),x=-1..1):
J1:=(term1+term2):
J1mod:=(Re(J1))^2+(Im(J1))^2:

###### J2#########################
A2:=int(exp((1+I*d)*Gamma*x)*sin(Omega1*(1+erf(tau))),x=-1..1):
A3:=sin(2*Omega1)*(exp((1+I*d)*Gamma*tau)-exp((1+I*d)*Gamma*t0))/(1+I*d):

J2:=-I*(A2+A3):

J2mod:=(Re(J2))^2+(Im(J2))^2:

#J3 same as J1differ in sign
term1:=(exp((1+I*d)*Gamma*tau)*(1+cos(2*Omega1))-cos(2*Omega)*exp((1+I*d)*Gamma*t0)+exp(-(1+I*d)*Gamma*t0))/(2*(1+I*d)):
term2:=0.5*int(exp((1+I*d)*Gamma*x)*cos(Omega1*(1+erf(tau))),x=-1..1):

J3:=term1+term2:
J3mod:=(Re(J3))^2+(Im(J3))^2:
J4:=-J2:
J4mod:=(Re(J4))^2+(Im(J4))^2:

#calculate the spectrum
Spec:=J1mod+J2mod:
#Spec:=J1mod*cos(theta/2)^2+J2mod+J3mod*sin(theta/2)^2
#      -0.5*Re(J3*J4*sin(theta)*exp(I*phi))+0.5*Re(J1*J4*sin(theta)*exp(-I*phi)):

with(plots):

Omega:=1:tau:=Pi:tau0:=1:Omega1:=0.5*Omega*tau0*sqrt(Pi):Gamma:=0.05:t0:=0.75:theta:=0:phi:=0:

tit:=sprintf("l=%a,W=%g,G=%g,q=%g,f=%g",l,Omega,Gamma,theta,phi);

"l=l,W=1,G=0.05,q=0,f=0"

P1:=plot(Spec,d=-350..350,axes=boxed,numpoints=200,title=tit,color=black,
         font=[2,3,18],thickness=2,tickmarks=[3,3],gridlines=false,
         labels=["",""],
         titlefont=[SYMBOL,14],font=[1,1,18],linestyle=1);

Normalize:= proc(P::specfunc(anything, PLOT))
  local A,Smax1;
  A:= op([1,1], P);
  Smax1:= max(A[..,2]);
  if A::list then A:= Matrix(A) end if;
  A[..,2]:= A[..,2]/Smax1;
  subsop([1,1]= A, P);
end proc:

P1:= Normalize(P1):
for kk from 2 to 5 do
  tau0:= kk*Pi;
  P||kk:= plot(Spec,d=-350..350,axes=boxed,numpoints=200,title=tit,color=black,
               font=[2,3,18],thickness=2,tickmarks=[3,3],gridlines=false,
               labels=["",""],
               titlefont=[SYMBOL,14],font=[1,1,18],linestyle=1);
  P||kk:= plottools:-translate(Normalize(P||kk), 0, kk-1)
od:

display([P||(1..5)],view=[-350..350,0..5]);

 

Download adel00.mw

@Rouben Rostamian  The OP gave a target rhs in which most of the original (diff-unrelated) terms were not expanded. Kitonum called collect (wrt R1) to undo that effect, but that is a slightly ad hoc or manual intervention.

I surmised that the OP wanted the remaining rhs terms left mostly as is, perhaps even more so than in the supplied target.

By using either collect or expand the diff terms can be initially separated. But by using collect for the initial separation of the derivatives there is less expansion to undo, for this example.

And if the leading sign is not crucial then my answer is shorter still.

There are other kinds of example where the effects of expand can be troublesome to undo. Sure an expanded call like sin(a+b) can be undone using combine. But there may be other trig products in the original which one doesn't want combined into a sum of trig calls on sums. Sometimes a frontend'ed call to expand can serve, but that's more effort to invoke.

And there are other related examples -- originally only partly expanded. Calling expand may expand too much, so that recovery of the very same extent of expansion is hard or practically impossible.

So it's my preference to not call expand, generally, if something else serves reasonably.

More specifically for this particular example: the OP wrote that he wanted the derivative terms to be collected, and he even provided a target that illustrated that. Now, the following accomplishes that but seems inferior because,
1) it calls both expand and collect, yet as I showed only collect is needed, and,
2) it expands all the remaining rhs terms, which would requires a rather ad hoc call to undo.

((L,R)->collect(L,diff)=-R)(selectremove(has,expand((rhs-lhs)(eqn)),diff));

@adel-00 This is still reasonably quick.

restart;

kernelopts(version);

`Maple 2019.0, X86 64 LINUX, Mar 9 2019, Build ID 1384062`

evalf(Int(exp((5+I*6)*x)*sin(1+erf(x)),x=-1.2..1.2));

49.09997652+1.408399186*I

restart;

igrand:=exp((5+I*d)*x)*sin(1+erf(x)):

Ref:=evalc(Re(igrand)):
Imf:=evalc(Im(igrand)):
 

f:=proc(c,dd) options remember, system;
  if not [c,dd]::list(numeric) then return 'procname'(_passed); end if;
  evalf(Int(eval(Ref,d=dd),x=-c..c, method=_d01ajc,_rest)
        +I*Int(eval(Imf,d=dd),x=-c..c, method=_d01ajc,_rest));
end proc:

CodeTools:-Usage( f(1.2, 6) );

memory used=395.27KiB, alloc change=0 bytes, cpu time=8.00ms, real time=14.00ms, gc time=0ns

49.09997652+1.408399186*I

CodeTools:-Usage( plot3d([Re(f(s,t,epsilon=1e-3)),
                          Im(f(s,t,epsilon=1e-3))],
                         s=0..1, t=-2*Pi..2*Pi, color=[red,blue]) );
 

memory used=127.04MiB, alloc change=37.00MiB, cpu time=1.03s, real time=974.00ms, gc time=122.67ms

 

Download evalf_int_3d.mw

@vv It can survive garbage collection while there is still some reference to it.

In your example it is still referenced by % (and %% and %%%).

@pauldaas I am guessing that you are showing a reduced example of what you eventually hope to accomplish. But it's difficult to make it the easiest and most robust without knowing in what more general ways you intend on using the code.

But here are two versions that might give you some hints. I've removed the `global` of the procedures because those seem unnecessary (the code assigns the returned results to R, and C seemed to serve no further purpose). I've removed calls to linalg commands. The procedures aF00111 and aM0011 are merged into a single procedure where the key aspect is that the 4th argument passed to it may be, say, F or M. And in one version I've removed L altogether, since there seems no real need to assign to the global names RA,MA,tA,yA when calling aFshear since the entries of R can be utilized directly.

pauldaas_01.mw

pauldaas_02.mw

Hopefully these still operate in a way that blends with your more general (and as yet unstated) purposes.

@Christian Wolinski Those work, too, for the polynomial p I created.

@MDD It only takes a fraction of a second to check hundreds of thousands of entries (in the worst situation that all the polynomials depend on x or y). It may not make much difference to you which you use.

restart;
randomize():

N := 10^5:
S := {seq(randpoly([x,y],degree=3),i=1..N),
      seq(x+randpoly([a,b,c,x,y],degree=3),i=1..N),
      seq(x+randpoly([a,b,c],degree=3),i=1..N)}:

func := S -> not andmap(has,S,{x,y}):

CodeTools:-Usage(func(S));
memory used=13.73MiB, alloc change=0 bytes, cpu time=96.00ms, real time=96.00ms, gc time=0ns
                             false

func4 := S -> ormap(s -> degree(s,{x,y})=0,S):

CodeTools:-Usage(func4(S));
memory used=36.62MiB, alloc change=0 bytes, cpu time=289.00ms, real time=289.00ms, gc time=0ns
                             false

nops(select(s -> degree(s,{x,y})=0,S));
                               0

nops(S);
                             300000

@mmcdara Of course it is necessary to utilize either the set/list of variables or the set/list of parameters. Even though I've edited my Answer (mostly for efficiency), every method I've written has utilized either the variables {x,y} or the parameters {a,b,c}. So I don't follow your point.

 

I've removed my Answer since the Question has been changed.

Is there some reason why you haven't posted a worksheet which (for you at least) reproduces the problem?

@EB1000 I am not aware of any practical way (or GUI option) to force the Library-generated context items to appear in the right-click popup in Maple 2019.

I also don't see any option to control the destination in the GUI's resource file.

If you could demonstrate that some other installation of Maple 2019 really did offer all the Library-generated items in the right-click popup menu then it'd be quite interesting in how it was configured.

I'm not even sure how I could force/fake it, except by writing a complicated Maplet which utilized the results from the ContextMenu command (and launched that Maplet from an edited version of that command), and which also knew about the ancilliary popup sub-Maplets.

You wrote it as "ConxtextMenu" instead of "ContextMenu".

Or are you saying that right-click on output gives you no popup at all?

@waseem 

You should figure out whether your formulas actually represent what you want.

Help1_ac_k.mw

@waseem I don't understand why you are undoing key aspects of my edits. You're latest attachment had more changes than just the introduction of additional terms.

I deliberately made several changes to your earlier worksheet, including:
1) Adjusting the definition of A so that it matched the formula from your earlier post's question about translation from Mathematica. This produces plots with zero imaginary component, suggesting that it's moving towards the right approach. I don't understand why you have reverted this.
2) Removed applications of evalf to Int calls which had extra options (since doing so removes them).
3) Increased Digits to 15.

In the following worksheet purely real results are obtained using either your latest S1 or the adjusted S1 formula to match your earlier post's definition in Mathematica. So I cannot say for sure which one is correct. Both produce purely real results for plotting, but different results. Likely only you can figure out which is correct.

I cannot know whether your formulas for the additional terms in c2 and e2 are correct. You might have made the same kind of "mistake" as earlier, with the grouping of terms in the denominator. Likely only you can figure out what is correct there.

You should think hard and carefully about those formulas. Just because you obtain purely real results from the integrations does not by itself mean that you have the formulas correct.

I have tried to make the inclusion of extra options (for the numeric integration) come immediately before the plotting, so that even if you once again splatter evalf calls in the formula definitions the plots might still compute. But only you can check that your formulas are correct.

It's possible that you could screw up my edits again, despite my latest efforts to guard against that. If you do I won't be looking at it any more.

I ran this in Maple 16, since I won't have access to Maple 13 until later in the say. But I suspect it will produce plots in your Maple 13 (as I tried the same kind of thing yesterday).

note: You legend values don't match the actual values which you're using for gamma2. I'll let you correct that.

restart:

Digits:=15:

d1:=0.2:d2:=0.6:L1:=0.2:L2:=0.2:F:=0.3:Br:=0.3:

Gr:=0.2: Nb:=0.1:Nt:=0.3:B:=1:B1:=0.7:m:=1:k:=0.1:

Ro:=1:R1:=1:q:=1:alpha:=Pi/4:

h:=z->piecewise( z<=d1,    1,

                 z<=d1+L1,   1-(gamma1/(2*Ro))*(1 + cos(2*(Pi/L1)*(z - d1 - L1/2))),

                        z<=B1-L2/2,  1 ,          

                    z<=B1,  1-(gamma2/(2*Ro))*(1 + cos(2*(Pi/L2)*(z - B1))),

                 z<=B1+L2/2,  R1-(gamma2/(2*Ro))*(1 + cos(2*(Pi/L2)*(z - B1))),

                 z<=B,    R1):

#A:=(-m^2/4)-(1/(4*k)):
A:=(-m^2/4)-(1/4*k):

#S1:=(h(z)^2)/(4*A)-ln(A*h(z)^2+1)*(1+h(z)^2)/4*A:
S1:=(h(z)^2)/4*A-ln(A*h(z)^2+1)*(1+h(z)^2)/4*A:

a2:=Int((1/S1),z=0..1):

b2:=Int((sin(alpha)/F),z=0..1):

c2:=(1/S1)*(-h(z)^6/(6912*A)-h(z)^4/(9216*A)+h(z)^2/(4608*A^3)+ln(1+A*h(z)^2)*(h(z)^6/(576*A)+h(z)^4/(512*A^2)-1/(4608*A^4))):

c3:=Int(c2,z=0..1):

c4:=2*Gr*(Nb-Nt)*c3:

e2:=(1/S1)*(-7*h(z)^4/(256*A)-h(z)^2/(128*A^2)+ln(1+A*h(z)^2)*(3*h(z)^4/(128*A)+h(z)^2/(32*A^2)+1/(128*A^3))):

e3:=Int(e2,z=0..1):

e4:=2*(Nt/Nb)*Br*e3:

l1:=-a2:

l2:=-b2-c4+e4:

Dp:=q*l1+l2:

 

igRe:=subsindets(Dp,specfunc(anything,Int),
                         u->Int(Re(op(1,u)),op(2,u),
                                   method=_d01ajc,epsilon=1e-6)):

plot([seq(eval(igRe,gamma2=j),j=[0,0.02,0.06])],gamma1=0.02..0.1,
     adaptive=false,
     legend = [gamma2 = 0.0,gamma2 = 0.02,gamma2 = 0.04],
     linestyle = [solid,dash,dot],
     color = [black,black,black],
     labels=[gamma1,'Re(Dp)'],
     gridlines=false, axes=boxed);

igIm:=subsindets(Dp,specfunc(anything,Int),
                         u->Int(Im(op(1,u)),op(2,u),
                                   method=_d01ajc,epsilon=1e-6)):

plot([seq(eval(igIm,gamma2=j),j=[0,0.02,0.06])],gamma1=0.02..0.1,
     adaptive=false,
     legend = [gamma2 = 0.0,gamma2 = 0.02,gamma2 = 0.04],
     linestyle = [solid,dash,dot],
     color = [black,black,black],
     labels=[gamma1,'Im(Dp)'],
     gridlines=false, axes=boxed);

 

``

Download Help1_acc.mw

@fatemeh1090 Does this work better in your LaTeX environment?

Naturally, you may wish to break the line (using \\ in the LaTex, or pasting it in by parts, or however you utilize $, $$ \begin{} or what have you).

end_ac2.mw

printf(StringTools:-SubstituteAll(
         StringTools:-SubstituteAll(latex(eval(new,1),output=string),
                     "\\mbox ",""),"\\tt ",""));

\sum _{m=1}^{M} \left( \sum _{k=1}^{N}C_{{{1}}_{{{i,m}}}}\,C_{{{1}}_{{{j,k}}}}\,v_{{{0}}_{{{k,m}}}} \right) -A_{0}\,H_{1}\,\sum _{m=1}^{M} \left( \sum _{k=1}^{N}C_{{{1}}_{{{i,m}}}}\,C_{{{1}}_{{{j,k}}}}\,v_{{{0}}_{{{k,m}}}} \right) -A_{1}\,F\sum _{k=1}^{N}C_{{{2}}_{{{i,k}}}}\,\psi_{\theta_{{{k,j}}}}+{\frac {A_{1}\,K_{4}\,\sum _{k=1}^{N}C_{{{1}}_{{{j,k}}}}\,\psi_{\theta_{{{k,i}}}}}{r_{i}}}+1/2\,{\frac {A_{0}\,K_{4}\,\sum _{k=1}^{N}C_{{{1}}_{{{j,k}}}}\,v_{{{0}}_{{{k,i}}}}}{r_{i}}}
First 220 221 222 223 224 225 226 Last Page 222 of 601