dharr

Dr. David Harrington

8482 Reputation

22 Badges

21 years, 34 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are answers submitted by dharr

In your differential equation below, you had "i (t)" which in 2-D math is interpreted as i*t, instead of "i(t)"

diff(i(t), t) = tau*delta*e(t)-(varepsilon+rho+mu)*i(t)

Use simplify(select(has,combinex,cos(omega*t))/cos(omega*t));

Here it is on a simpler example.

Download select.mw

Edit: I agree this doesn't work for negative powers of x.

Note also that 90.0 is different from 90.00.

Download table.mw

So you will have to convert to a known form. Since they are integers, you can use round(x).

Edit: in your case of a Matrix, you can use:

map(x->if type(x,numeric) then round(x) else x end if,data);

 

 

 

Not sure exactly what you want here and I don't want to retype your expression in, but for example

y:=a/(b^2+c^2)+d/(b^2+c^2)^2:
normal(y);

gives 

(a*b^2+a*c^2+d)/(b^2+c^2)^2

 

If mass is a label component, then you can right-click on it, choose "component properties" and then under "font color" set RGB values or choose a color from the palette.

Not sure if y^2 is to count as well as products, but to count only products:

select(type,ListTools:-Flatten(w),`*`);
nops(%);

A.B-1 is rank 1 so there is only one nonzero eigenvalue. If this eigenvalue is found symbolically, then parameter values may be varied in plots as shown.
 

restart

with(LinearAlgebra); A := Matrix(6, 6, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = alpha[1]*S[p], (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = beta, (4, 4) = 0, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0, (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = 0}); B := Matrix(6, 6, {(1, 1) = mu, (1, 2) = tau, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = e[o], (2, 1) = 0, (2, 2) = tau+mu, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = beta+eta[1]+sigma+mu, (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = (1-delta)*alpha[2]-mu, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = alpha[2]*delta, (5, 5) = mu+eta[2], (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = mu+e[o]}); C := A.(1/B); Rank(C); evs := Eigenvalues(C); eig := op(`minus`({entries(evs, nolist)}, {0}))

A := Matrix(6, 6, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = alpha[1]*S[p], (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = beta, (4, 4) = 0, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0, (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = 0})

B := Matrix(6, 6, {(1, 1) = mu, (1, 2) = tau, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = e[o], (2, 1) = 0, (2, 2) = tau+mu, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = beta+eta[1]+sigma+mu, (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = (1-delta)*alpha[2]-mu, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = alpha[2]*delta, (5, 5) = mu+eta[2], (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = mu+e[o]})

C := Matrix(6, 6, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = alpha[1]*S[p]/(beta+eta[1]+sigma+mu), (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = beta/(beta+eta[1]+sigma+mu), (4, 4) = 0, (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0, (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = 0})

1

evs := Vector(6, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0, (6) = alpha[1]*S[p]/(beta+eta[1]+sigma+mu)})

alpha[1]*S[p]/(beta+eta[1]+sigma+mu)

params := {beta = .5, delta = .2115, mu = 0.2041e-1, sigma = .9, tau = .33, S[p] = 34.722406639004, alpha[1] = 0.2e-3, alpha[2] = .2, e[o] = .33, eta[1] = 0.96e-1, eta[2] = 0.2485e-2}

{beta = .5, delta = .2115, mu = 0.2041e-1, sigma = .9, tau = .33, S[p] = 34.722406639004, alpha[1] = 0.2e-3, alpha[2] = .2, e[o] = .33, eta[1] = 0.96e-1, eta[2] = 0.2485e-2}

Plot vs mu, for example

plot(eval(eig, remove(has, params, mu)), mu = 0 .. 1)

 


 

Download eval.mw

For regular 1-D input, a rectangle surrounds the parenthesis that matches the one next to the cursor (vertical line here)

If you don't try to see R0 (terminate with colon), then implicitplot is fine with gridrefine=3 (gridrefine=10 runs into a memory allocation on my machine), and the data is extracted with plottools:-getdata without issue.

implictplot.mw

The ISOSURFACE plot structure (see ?plot,structure) is used internally by implicitplot3d to draw a surface where a function is zero over an evenly spaced grid of values, so it is close to your dataarray, assuming your x,y,z values are evenly spaced. So to get a red surface enclosing -1 values can be done as below. Not sure it makes sense to color the rest of space green since then you couldn't see anything.

restart;with(plots):

Generate dataarray with -1 values within an ellipse, +1 outside

ellipse:=(x,y,z)->if x^2/0.2+y^2/0.8+z^2/0.3 < 1 then -1 else 1 end if;

proc (x, y, z) options operator, arrow; if x^2/.2+y^2/.8+z^2/.3 < 1 then -1 else 1 end if end proc

x:=Vector(1..10,i->(i-5.5)/5):
y:=Vector(1..10,i->(i-5.5)/5):
z:=Vector(1..10,i->(i-5.5)/5):
dataarray:=Array(1..10,1..10,1..10,(i,j,k)->ellipse(x[i],y[j],z[k]),datatype=float[8],order=C_order):

Fill array required for ISOSURFACE structure

isoarray:=Array(1..10,1..10,1..10,1..4,datatype=float[8],order=C_order):

for ix to 10 do
  for iy to 10 do
    for iz to 10 do
      isoarray[ix,iy,iz,1]:=x[ix];
      isoarray[ix,iy,iz,2]:=y[iy];
      isoarray[ix,iy,iz,3]:=z[iz];
      isoarray[ix,iy,iz,4]:=dataarray[ix,iy,iz];
   end do;
 end do;
end do:

display(PLOT3D(ISOSURFACE(isoarray)),view=[-1..1,-1..1,-1..1],color=red);

 


 

Download isosurface2.mw

 

Try arctan(-diff(fy,t),diff(fx,t)), or perhaps arctan(diff(fy,t),diff(fx,t)) I didn't follow the details, but it removes the discontinuity.

It's just very slow, especially for small and large times. You are doing an integral within an integral. If you change the plot range to 1..1000 then you do get a plot in a few seconds.

In addition to @tomleslie 's solutions there is one real one between 0 and 1. I have also made the mininum number of changes to convert from the old linalg package to the LinearAlgebra package. To more consistently find the roots, you could use the NextZero routine in the RootFinding package.

I can't see any typos, so I don't know where the 0.5 root could come from.


 

restart

with(LinearAlgebra)

V0 := 1

1

a := 2

2

b := 1

1

assume(En > 0)

ks := sqrt(2*En)

2^(1/2)*En^(1/2)

qs := sqrt(2*(V0-En))

(2-2*En)^(1/2)

psi11 := proc (x) options operator, arrow; A1*exp(qs*x)+B1*exp(-qs*x) end proc

proc (x) options operator, arrow; A1*exp(qs*x)+B1*exp(-qs*x) end proc

psi21 := proc (x) options operator, arrow; A2*exp(I*ks*x)+B2*exp(-I*ks*x) end proc

proc (x) options operator, arrow; A2*exp(I*ks*x)+B2*exp(-I*ks*x) end proc

lp := a+b

3

psi12 := proc (x) options operator, arrow; exp(I*Kp*lp)*(A1*exp(qs*(x-lp))+B1*exp(-qs*(x-lp))) end proc

proc (x) options operator, arrow; exp(I*Kp*lp)*(A1*exp(qs*(x-lp))+B1*exp(-qs*(x-lp))) end proc

psi22 := proc (x) options operator, arrow; exp(I*Kp*lp)*(A2*exp(I*ks*(x-lp))+B2*exp(-I*ks*(x-lp))) end proc

proc (x) options operator, arrow; exp(I*Kp*lp)*(A2*exp(I*ks*(x-lp))+B2*exp(-I*ks*(x-lp))) end proc

eq1 := psi11(0) = psi21(0)

A1+B1 = A2+B2

eq2 := (D(psi11))(0)-(D(psi21))(0)

A1*(2-2*En)^(1/2)-B1*(2-2*En)^(1/2)-I*A2*2^(1/2)*En^(1/2)+I*B2*2^(1/2)*En^(1/2)

eq3 := expand(psi21(a)-psi12(a))

A2*(exp(I*2^(1/2)*En^(1/2)))^2+B2/(exp(I*2^(1/2)*En^(1/2)))^2-(exp(I*Kp))^3*A1/exp((2-2*En)^(1/2))-(exp(I*Kp))^3*B1*exp((2-2*En)^(1/2))

eq4 := expand((D(psi21))(a)-(D(psi12))(a))

I*A2*2^(1/2)*En^(1/2)*(exp(I*2^(1/2)*En^(1/2)))^2-I*B2*2^(1/2)*En^(1/2)/(exp(I*2^(1/2)*En^(1/2)))^2-(exp(I*Kp))^3*A1*(2-2*En)^(1/2)/exp((2-2*En)^(1/2))+(exp(I*Kp))^3*B1*(2-2*En)^(1/2)*exp((2-2*En)^(1/2))

row1 := Vector[row]([1, 1, -1, -1])

row1 := Vector[row](4, {(1) = 1, (2) = 1, (3) = -1, (4) = -1})

row2 := Vector[row]([coeff(eq2, A1), coeff(eq2, B1), coeff(eq2, A2), coeff(eq2, B2)])

row2 := Vector[row](4, {(1) = (2-2*En)^(1/2), (2) = -(2-2*En)^(1/2), (3) = -I*2^(1/2)*En^(1/2), (4) = I*2^(1/2)*En^(1/2)})

row3 := Vector[row]([coeff(eq3, A1), coeff(eq3, B1), coeff(eq3, A2), coeff(eq3, B2)])

row3 := Vector[row](4, {(1) = -(exp(I*Kp))^3/exp((2-2*En)^(1/2)), (2) = -(exp(I*Kp))^3*exp((2-2*En)^(1/2)), (3) = (exp(I*2^(1/2)*En^(1/2)))^2, (4) = 1/(exp(I*2^(1/2)*En^(1/2)))^2})

row4 := Vector[row]([coeff(eq4, A1), coeff(eq4, B1), coeff(eq4, A2), coeff(eq4, B2)])

row4 := Vector[row](4, {(1) = -(exp(I*Kp))^3*(2-2*En)^(1/2)/exp((2-2*En)^(1/2)), (2) = (exp(I*Kp))^3*(2-2*En)^(1/2)*exp((2-2*En)^(1/2)), (3) = I*2^(1/2)*En^(1/2)*(exp(I*2^(1/2)*En^(1/2)))^2, (4) = -I*2^(1/2)*En^(1/2)/(exp(I*2^(1/2)*En^(1/2)))^2})

C := Matrix(4, 4, 0)

C := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 1, (1, 3) = -1, (1, 4) = -1, (2, 1) = (2-2*En)^(1/2), (2, 2) = -(2-2*En)^(1/2), (2, 3) = -I*2^(1/2)*En^(1/2), (2, 4) = I*2^(1/2)*En^(1/2), (3, 1) = -(exp(I*Kp))^3/exp((2-2*En)^(1/2)), (3, 2) = -(exp(I*Kp))^3*exp((2-2*En)^(1/2)), (3, 3) = (exp(I*2^(1/2)*En^(1/2)))^2, (3, 4) = 1/(exp(I*2^(1/2)*En^(1/2)))^2, (4, 1) = -(exp(I*Kp))^3*(2-2*En)^(1/2)/exp((2-2*En)^(1/2)), (4, 2) = (exp(I*Kp))^3*(2-2*En)^(1/2)*exp((2-2*En)^(1/2)), (4, 3) = I*2^(1/2)*En^(1/2)*(exp(I*2^(1/2)*En^(1/2)))^2, (4, 4) = -I*2^(1/2)*En^(1/2)/(exp(I*2^(1/2)*En^(1/2)))^2})

for i to 4 do C[1, i] := row1[i]; C[2, i] := row2[i]; C[3, i] := row3[i]; C[4, i] := row4[i] end do

C

Matrix([[1, 1, -1, -1], [(2-2*En)^(1/2), -(2-2*En)^(1/2), -I*2^(1/2)*En^(1/2), I*2^(1/2)*En^(1/2)], [-(exp(I*Kp))^3/exp((2-2*En)^(1/2)), -(exp(I*Kp))^3*exp((2-2*En)^(1/2)), (exp(I*2^(1/2)*En^(1/2)))^2, 1/(exp(I*2^(1/2)*En^(1/2)))^2], [-(exp(I*Kp))^3*(2-2*En)^(1/2)/exp((2-2*En)^(1/2)), (exp(I*Kp))^3*(2-2*En)^(1/2)*exp((2-2*En)^(1/2)), I*2^(1/2)*En^(1/2)*(exp(I*2^(1/2)*En^(1/2)))^2, -I*2^(1/2)*En^(1/2)/(exp(I*2^(1/2)*En^(1/2)))^2]])

chareq := Determinant(C)

2*((2*I)*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*(exp(I*Kp))^6*exp((2-2*En)^(1/2))*(exp(I*2^(1/2)*En^(1/2)))^2-I*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2*(exp(I*2^(1/2)*En^(1/2)))^4-I*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*(exp(I*Kp))^3*(exp(I*2^(1/2)*En^(1/2)))^4+2*En*(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2*(exp(I*2^(1/2)*En^(1/2)))^4-I*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2-(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2*(exp(I*2^(1/2)*En^(1/2)))^4-2*En*(exp(I*Kp))^3*(exp(I*2^(1/2)*En^(1/2)))^4-I*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*(exp(I*Kp))^3+(2*I)*2^(1/2)*En^(1/2)*(2-2*En)^(1/2)*exp((2-2*En)^(1/2))*(exp(I*2^(1/2)*En^(1/2)))^2+(exp(I*Kp))^3*(exp(I*2^(1/2)*En^(1/2)))^4-2*En*(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2+(exp(I*Kp))^3*(exp((2-2*En)^(1/2)))^2+2*En*(exp(I*Kp))^3-(exp(I*Kp))^3)/(exp((2-2*En)^(1/2))*(exp(I*2^(1/2)*En^(1/2)))^2)

chareq0 := simplify(subs(Kp = 0, chareq))

(-(2*I)*(2-2*En)^(1/2)*2^(1/2)*En^(1/2)+4*En-2)*exp(-(2-2*En)^(1/2)-(2*I)*2^(1/2)*En^(1/2))+(-(2*I)*(2-2*En)^(1/2)*2^(1/2)*En^(1/2)-4*En+2)*exp(-(2-2*En)^(1/2)+(2*I)*2^(1/2)*En^(1/2))+(-(2*I)*(2-2*En)^(1/2)*2^(1/2)*En^(1/2)-4*En+2)*exp((2-2*En)^(1/2)-(2*I)*2^(1/2)*En^(1/2))+(-(2*I)*(2-2*En)^(1/2)*2^(1/2)*En^(1/2)+4*En-2)*exp((2-2*En)^(1/2)+(2*I)*2^(1/2)*En^(1/2))+(8*I)*(2-2*En)^(1/2)*2^(1/2)*En^(1/2)

Real parts are all zero for En<1

plot(Re(chareq0), En = 0 .. 3, color = red, thickness = 3)

Imaginary parts are all zero for En>1

plot(Im(chareq0), En = 0 .. 3, color = red, thickness = 3)

sol1 := fsolve(chareq0, En = .2 .. .4); sol2 := fsolve(chareq0, En = 2 .. 2.5)

.2669813621+0.*I

2.375133245-0.*I

 


 

Download qm_maple_-_periodic_potentials.mw
 

As @acer suggested, they have different compressions (and formats). Corel PhotoPaint reports the original 125 KB file is 1 bit B&W, 300 dpi, CCITT group 3 subformat (compression), and the 133 KB one written by Maple is 72 dpi, 8 bit grayscale and LZW compression. LZW is a lossless compression, but it is interesting that the output resolution is lower.

Edit: aside from the resolution issue, the above is as indicated on the ImageTools[Formats] help page.

 

There was nothing wrong with  the actual code, but it hadn't been entered after a prompt (in a worksheet) and was somehow two separate regions. If you enter 1-D code as you did, you need to format it yourself. You get some nicer formatting with a code edit region if you are going to enter a lot of code.

For this site, uploading a worksheet as you did is probably best.

proc.mw

Edit: Using a startup code edit region for initialization and procedure definitions can be a nice way to do it.

First 60 61 62 63 64 65 66 Last Page 62 of 83