dharr

Dr. David Harrington

8270 Reputation

22 Badges

20 years, 355 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

If you create the Matrix with option shape = symmetric, then you will get only real eigenvalues and eigenvectors, and Maple will use a more efficient method specialized for symmetric matrices.

(If you just want to get rid of the +0*I after the fact, you can use simplify(..., zero)).

You didn't say how you want to export your plot, but if I assume you want vector graphics then there are two possibilities, encapsulated postscript (EPS) or SVG. (possibly also PDF but I've never tried it)

If I make a plot with no background, say plot(sin(x),axes=none): and export it as EPS with the right-click menu, then look at it with CorelDraw I find it has a white background (which I usually delete and then process further), so this does not work for you.

However, exporting as SVG gives a file that does not have a background, just the curve, so this is what you want.

If you actually want to export as a bitmap image (with loss of resolution), then I don't have much experience with that. Which formats would you want then?

An extract from the ?updates,Maple2017,Performance help page: "Maple 2017 includes a new compiled C implementation of the FGLM algorithm for computing a lexicographic Groebner basis from a total degree basis when there are a finite number of solutions.  This routine is used automatically by Groebner:-Basis when applicable and by the solve command when solving polynomial systems.  The example below runs about 200 times faster in Maple 2017."

The ?updates,Maple2018,index help page and the current help page for ?Groebner,Basis say "The Groebner[Basis] command was updated in Maple 2018", which I assume means the command itself has changed but not necessarily the algorithms.

(If you are using the bases for solving systems of polynomial equations, then there are new methods that don't use Groebner bases that may be more efficient.)

If I understand correctly what you mean, use ctrl-shift-K to insert above and ctrl-shift-J to insert below. (command-shift-K and command-shift-J on Mac). See ?worksheet,reference,hotmac or ..hotwin or .. hotunix.

The default behavior was changed in Maple 2020, see ?updates,Maple2020,IntegralTransforms.

To get the behavior you want, use setup(computederivatives = false);

Download laplace.mw

This is an answer to the followup question, now deleted, about plotting the solution in cartesian coordinates. Here is an example:

PDE_upd_5.mw

Note that VectorCalculus:-Laplacian(u(xi, eta), 'bipolar'[xi, eta]) assumes a=1, so I substituted your earlier laplacian.

Since you have already the functions x(xi,eta) and y(xi,eta), you can use the parametric version of contourplot.

PDE_upd_5.mw

I would probably play around with custom contour values because your large spike dominates and so the contours near zero do not have good resolution, but the I think you cannot then use the colorbar.

NOTE: I replaced VectorCalculus:-Laplacian(u(xi, eta), 'bipolar'[xi, eta]) with your earlier hand-calculated Laplacian, since the built-in one uses a = 1, which you had before but is not applicable here. VectorCalculus is supposed to have a mechanism for changing the a parameter (SetCoordinateParameters) but I couldn't get it to work with Laplacian. 

Yes, your substitutions missed an x. You can capture this with 

eqs := {coeffs(collect(numer(normal(eq)), {X, Y, Z, x}, 'distributed'), {X, Y, Z, x})}

but I think that you cannot constrain tanh(k*x + p*y - t*w) together as one variable, since x, y, and t are independent. If the ln was not there you could expand(tanh(k*x + p*y - t*w)) and substitute the individual sinh, cosh etc, or just convert to exp, but in both cases the ln is a problem.

I would almost always use simplify for this sort of thing, not is.

restart

d := proc (i, j) options operator, arrow; (x[i]-x[j])^2+(y[i]-y[j])^2 end proc

proc (i, j) options operator, arrow; (x[i]-x[j])^2+(y[i]-y[j])^2 end proc

q1:=d(1,2)*d(1,2)*d(3,4)+d(1,3)*d(1,3)*d(2,4)+d(1,4)*d(1,4)*d(2,3)+d(2,3)*d(2,3)*d(1,4)
+d(2,4)*d(2,4)*d(1,3)+d(3,4)*d(3,4)*d(1,2)+d(1,2)*d(2,3)*d(3,1)+d(1,2)*d(2,4)*d(4,1)
+d(1,3)*d(3,4)*d(4,1)+d(2,3)*d(3,4)*d(4,2);

((x[1]-x[2])^2+(y[1]-y[2])^2)^2*((x[3]-x[4])^2+(y[3]-y[4])^2)+((x[1]-x[3])^2+(y[1]-y[3])^2)^2*((x[2]-x[4])^2+(y[2]-y[4])^2)+((x[1]-x[4])^2+(y[1]-y[4])^2)^2*((x[2]-x[3])^2+(y[2]-y[3])^2)+((x[2]-x[3])^2+(y[2]-y[3])^2)^2*((x[1]-x[4])^2+(y[1]-y[4])^2)+((x[2]-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+(y[1]-y[3])^2)*((x[3]-x[4])^2+(y[3]-y[4])^2)*((x[4]-x[2])^2+(y[4]-y[2])^2)+((x[1]-x[4])^2+(y[1]-y[4])^2)*((x[4]-x[3])^2+(y[4]-y[3])^2)*((x[3]-x[2])^2+(y[3]-y[2])^2)+((x[2]-x[3])^2+(y[2]-y[3])^2)*((x[3]-x[1])^2+(y[3]-y[1])^2)*((x[1]-x[4])^2+(y[1]-y[4])^2)+((x[2]-x[1])^2+(y[2]-y[1])^2)*((x[1]-x[3])^2+(y[1]-y[3])^2)*((x[3]-x[4])^2+(y[3]-y[4])^2)+((x[2]-x[4])^2+(y[2]-y[4])^2)*((x[4]-x[1])^2+(y[4]-y[1])^2)*((x[1]-x[3])^2+(y[1]-y[3])^2)+((x[2]-x[1])^2+(y[2]-y[1])^2)*((x[1]-x[4])^2+(y[1]-y[4])^2)*((x[4]-x[3])^2+(y[4]-y[3])^2)+((x[3]-x[1])^2+(y[3]-y[1])^2)*((x[1]-x[2])^2+(y[1]-y[2])^2)*((x[2]-x[4])^2+(y[2]-y[4])^2)+((x[3]-x[2])^2+(y[3]-y[2])^2)*((x[2]-x[1])^2+(y[2]-y[1])^2)*((x[1]-x[4])^2+(y[1]-y[4])^2)

simplify(q1-q2)

0

``

Download distances.mw

There were errors in V. Now it works but is very slow, even with only a 10 x 10 grid. There are common expressions in the integrand that some hand coding could optimize. One could also play with some of the integration options (method, errors).

restart; with(plots); with(LinearAlgebra); with(Student[VectorCalculus]); V := proc (k, x, t) options operator, arrow; -((1/2)*I)*exp(I*k*x-k^2*t)*(1/(k-I)+1/(k+I)-k*(1/(k^2+I)+1/(k^2-I)))/Pi end proc

proc (k, x, t) options operator, arrow; Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`*`(I, Student:-VectorCalculus:-`*`(2, Pi)^Student:-VectorCalculus:-`-`(1)), exp(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`*`(I, k), x), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(k^2, t))))), Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`+`(k, Student:-VectorCalculus:-`-`(I))^Student:-VectorCalculus:-`-`(1), Student:-VectorCalculus:-`+`(k, I)^Student:-VectorCalculus:-`-`(1)), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(k, Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`+`(k^2, I)^Student:-VectorCalculus:-`-`(1), Student:-VectorCalculus:-`+`(k^2, Student:-VectorCalculus:-`-`(I))^Student:-VectorCalculus:-`-`(1))))))) end proc

V(k, x, t)

-((1/2)*I)*exp(I*k*x-k^2*t)*(1/(k-I)+1/(k+I)-k*(1/(k^2+I)+1/(k^2-I)))/Pi

phi1 := (1/8)*Pi; phi2 := 7*Pi*(1/8); k1 := proc (r) options operator, arrow; r*exp(I*phi1) end proc; k2 := proc (r) options operator, arrow; r*exp(I*phi2) end proc; dk1 := proc (r) options operator, arrow; diff(k1(r), r) end proc; dk2 := proc (r) options operator, arrow; diff(k2(r), r) end proc

Integrand now real

integr := `assuming`([simplify(evalc(V(k1(r), x, t)*dk1(r)-V(k2(r), x, t)*dk2(r)))], [r > 0])

r*exp(-(1/2)*(r*t*2^(1/2)+2*cos((3/8)*Pi)*x)*r)*(((r^8-2*r^4+1)*2^(1/2)-2*r^6-2*r^2)*cos((1/2)*(r*t*2^(1/2)-2*cos((1/8)*Pi)*x)*r)+sin((1/2)*(r*t*2^(1/2)-2*cos((1/8)*Pi)*x)*r)*(r^8*2^(1/2)+2*r^6-2*r^2-2^(1/2)))/((r^8+1)*(1+r^4+r^2*2^(1/2))*Pi)

evalf(eval(integr, {r = 2, t = 1, x = 1}))

0.1505152135e-2

u1 := unapply(Int(integr, r = 0 .. infinity), x, t)

proc (x, t) options operator, arrow; Int(r*exp(-(1/2)*(r*t*2^(1/2)+2*cos((3/8)*Pi)*x)*r)*(((r^8-2*r^4+1)*2^(1/2)-2*r^6-2*r^2)*cos((1/2)*(r*t*2^(1/2)-2*cos((1/8)*Pi)*x)*r)+sin((1/2)*(r*t*2^(1/2)-2*cos((1/8)*Pi)*x)*r)*(r^8*2^(1/2)+2*r^6-2*r^2-2^(1/2)))/((r^8+1)*(1+r^4+r^2*2^(1/2))*Pi), r = 0 .. infinity) end proc

Now real - but slow

evalf(u1(2, 1))

0.5826332317e-1

u := proc (x, t) options operator, arrow; exp(-x/sqrt(2))*cos(t-x/sqrt(2))+u1(x, t) end proc

proc (x, t) options operator, arrow; Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(exp(Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(x, sqrt(2)^Student:-VectorCalculus:-`-`(1)))), cos(Student:-VectorCalculus:-`+`(t, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(x, sqrt(2)^Student:-VectorCalculus:-`-`(1)))))), u1(x, t)) end proc

Very slow but it works

CodeTools:-Usage(plot3d(u(x, t), x = 0 .. 3, t = 0 .. 2*Pi, grid = [10, 10], adaptmesh = false, axes = boxed, shading = zhue, style = surface, labels = ["x", "t", "u(x,t)"]))

memory used=14.20GiB, alloc change=32.00MiB, cpu time=93.38s, real time=80.66s, gc time=22.44s

NULL

Download fokas_method.mw

 

Here's an attempt at a ternary plot. If you want tick marks along the edges of the triangle, that would be tricky to do, but undoubtedly possible. (One edge would be easy because it is along the x-axis.)

restart

with(plots); with(plottools)

prob of m and k successes in N trials with prob p,q per trial

trinomial := proc (m, k, N, p, q) options operator, arrow; factorial(N)*p^m*q^k*(1-p-q)^(N-m-k)/(factorial(m)*factorial(k)*factorial(N-m-k)) end proc

proc (m, k, N, p, q) options operator, arrow; factorial(N)*p^m*q^k*(1-p-q)^(N-m-k)/(factorial(m)*factorial(k)*factorial(N-m-k)) end proc

Ternary coords for m = N at (N,0), k=N at (1/2,sqrt(3)/2)*N, third one =N at the origin. - see  https://en.wikipedia.org/wiki/Ternary_plot

tcoords := proc (m, k) options operator, arrow; (2*m+k)/2., sqrt(3)*k/2. end proc

proc (m, k) options operator, arrow; (2*m+k)/2., sqrt(3)*k/2. end proc

triangle := proc (N) options operator, arrow; polygon([[tcoords(0, N), 0], [tcoords(N, 0), 0], [0, 0, 0]], color = yellow) end proc

pins := proc (N, p, q) options operator, arrow; [seq(seq(line([tcoords(m, k), 0], [tcoords(m, k), trinomial(m, k, N, p, q)], color = red, thickness = 3), m = 0 .. N-k), k = 0 .. N)] end proc

Warning, (in pins) `k` is implicitly declared local

Warning, (in pins) `m` is implicitly declared local

lbls := proc (N) options operator, arrow; textplot3d({[0, 0, 0, cat("var3 = ", N), align = [below, right]], [(1/2)*N, (1/2)*sqrt(3)*N, 0, cat("var2 = ", N), align = [below, right]], [N, 0, 0, cat("var1 = ", N), align = [below, left]]}) end proc

N := 20

20

display(pins(N, .2, .5), triangle(N), lbls(N), axes = normal, labels = ["", "", prob], axis[1, 2] = [color = white])

NULL

Download trinomial.mw

Here's how I would follow the Youtube simplifications in Maple land. I also show that term1 and term2 are the some parameters. Edit: I mistakenly thought that @Carl Love was using t for x, but I now see he was referring to a different post.
 

restart

We want to show that term 1 = term2. We follow the procedure here

term1 := (2*cos(2^n*x)+1)/(2*cos(x)+1)

(2*cos(2^n*x)+1)/(2*cos(x)+1)

term2 := product(2*cos(2^k*x)-1, k = 0 .. n-1)

product(2*cos(2^k*x)-1, k = 0 .. n-1)

Let's write out the factors in the product up to n=6

f := [op(eval(term2, n = 6))]

[2*cos(x)-1, 2*cos(2*x)-1, 2*cos(4*x)-1, 2*cos(8*x)-1, 2*cos(16*x)-1, 2*cos(32*x)-1]

We multiply the first factor by g (the first factor but with a sign change); just (a-b)*(a+b) = a^2-b^2

g := 2*cos(x)+1; f1 := expand(g*f[1])

2*cos(x)+1

4*cos(x)^2-1

We show it is equal to the second factor but with a sign change.

f1 := combine(f1)

1+2*cos(2*x)

So similarly multiplying by the second factor and then combining we get the third factor with a sign change

f1*f[2]; f2 := combine(%)

(1+2*cos(2*x))*(2*cos(2*x)-1)

2*cos(4*x)+1

So continuing up to the last term we will get

fn_minus_1 := 2*cos(2^n*x)+1

2*cos(2^n*x)+1

which we need to divide by the g we multiplied by originally to get the final result

result := fn_minus_1/g

(2*cos(2^n*x)+1)/(2*cos(x)+1)

Maple gives this form immediately if we evaluate term2 for a given n, but can't do the case of general n.

eval(term1, n = 6)

(2*cos(64*x)+1)/(2*cos(x)+1)

Check for some specific params

params := {n = 1, x = (1/6)*Pi}

{n = 1, x = (1/6)*Pi}

rationalize(eval(term1, params)); eval(term2, params)

3^(1/2)-1

3^(1/2)-1

NULL

Download MapleLand.mw

OK, I now understand you want the plot of u(y) to look like the one you just posted, with a slope of zero at y=0 and going down to u(1) = 1.
Now psi = D(u), but in the odeplot that you labelled u(x,y) you asked to plot D(psi), which is not u. u is instead the integral of psi.

pltN[j] := odeplot(
        dsol[j], [y, D(psi)(y)], y = 0..1,
        labels = [typeset(y), typeset(u(x, y))], labelfont = ["TIMES", "italic", 18],

So just add another ODE to your system

diff(u(y),y) = psi(y), u(1)=1 

and plot u(y).

Edit: Of course you will have to change your boundary conditions that assumed D(psi) = u instead of psi = D(u)

Yes, that seems like a problem. Using LinearSolve is faster. (If you can use a float calculation NullSpace is much faster.)

restart; M := LinearAlgebra:-RandomMatrix(200, 500, generator = -50 .. 50)

st := time(); linalg[kernel](M); nops(%); time()-st

32.109

st := time(); X := LinearAlgebra:-LinearSolve(M, `<,>`(`$`(0, 200))); time()-st

24.984

``

nops(indets(X))

300

NULL

NULL

NULL

Download NullSpace_vs_kernel.mw

Edit: If you want it in the same format as NullSpace:

NullSpace.mw

What do you want to plot? You could use plot3d to plot abs(FF) vs x and P1 or Re(FF) vs x and P1 or Im(FF) vs x and P1 or argument(FF) vs x and P1. Here I use complexplot 3d to plot abs(FF) coloured by the phase. The plot is not very informative, probably because your function has numbers with wildly different exponents, e.g. 10^(-2750) and 10^5 but these numbers have only about 5 digit accuracy. Probably you should go back to a version in symbolic form and then evaluate to numeric form with a high setting of Digits so you don't lose accuracy.

PLOT11.mw

Edit: If you really want to find where the function is zero with implicit plot, you should explore more limited regions - the plots above can be a guide for this. I suspect again the quality of your function is making it hard for the internal solver. 

1 2 3 4 5 6 7 Last Page 1 of 82