dharr

Dr. David Harrington

7720 Reputation

22 Badges

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

Not optimum. Adapted from some old code I had.

restart;

chexagons:=proc(n::posint,a::positive)
   # n = lattice size, a = hexagon size
   local i, j, imax, hexesA, hexesB, hexesC, hex;
   uses plottools;
   # hex returns coords of hexagon of edge length a centred at x,y.
   hex := (x,y,a) -> [[x+a,y],[x+a/2,y+a*sqrt(3)/2],[x-a/2,y+a*sqrt(3)/2],[x-a,y],[x-a/2,y-a*sqrt(3)/2],[x+a/2,y-a*sqrt(3)/2]];
   hexesA := NULL; hexesB := NULL; hexesC := NULL;
   for i to n do for j to n do
     if j-i mod 3 =0 then
       if i mod 3 = 0 then hexesA := hexesA, hex((j-1)*a+(i-1)*a/2,-(i-1)*a*sqrt(3)/2,a) end if;
       if i mod 3 = 1 then hexesB := hexesB, hex((j-1)*a+(i-1)*a/2,-(i-1)*a*sqrt(3)/2,a) end if;
       if i mod 3 = 2 then hexesC := hexesC, hex((j-1)*a+(i-1)*a/2,-(i-1)*a*sqrt(3)/2,a) end if;
     end if;
   end do end do;
   plots:-display(polygon([hexesA],color=red), polygon([hexesB],color=blue), polygon([hexesC],color=green),
           scaling=constrained,axes=none)
end proc:

chexagons(10,1);

 

Download hexagons.mw

This is an answer for (1). For (2), would you please upload your worksheet (using green up-arrow) so we can understand more clearly what you want.

p.s. q_d seems to be ignored here; not sure what that means or what you wanted.

restart

with(DynamicSystems)

The default discretetimevar is q, so to use n

SystemOptions(discretetimevar = n)

q

sys2 := StateSpace([u(n) = K_virt*(q_a(n)-q_d)+D_virt*(q_a(n)-q_a(n-1))/T], inputvariable = [q_a(n)], outputvariable = [u(n)], discrete = true, sampletime = T)

Look at the matrices. Since we have c <> 0, the state variable is being used and is implicitly the delayed value - note that c is the coefficient of q_a(n-1)

PrintSystem(sys2)

"[[[`State Space`],[`discrete; sampletime = T`],[`1 output(s); 1 input(s); 1 state(s)`],[inputvariable=[q_a(n)]],[outputvariable=[u(n)]],[statevariable=[x1(n)]],[a=[[[0]]]],[b=[[[1]]]],[c=[[[-D_virt/T]]]],[d=[[[(K_virt T+D_virt)/T]]]]]"

If you want to call it q_a_delayed, you have to explicitly invoke it in the difference equations

sys3 := StateSpace([u(n) = K_virt*(q_a(n)-q_d)+D_virt*(q_a(n)-q_a_delayed(n))/T, q_a_delayed(n) = q_a(n-1)], inputvariable = [q_a(n)], outputvariable = [u(n)], statevariable = [q_a_delayed(n)], discrete = true, sampletime = T)

Same matrices

PrintSystem(sys3)

"[[[`State Space`],[`discrete; sampletime = T`],[`1 output(s); 1 input(s); 1 state(s)`],[inputvariable=[q_a(n)]],[outputvariable=[u(n)]],[statevariable=[q_a_delayed(n)]],[a=[[[0]]]],[b=[[[1]]]],[c=[[[-D_virt/T]]]],[d=[[[(K_virt T+D_virt)/T]]]]]"

NULL

Download DynamicSystems.mw

In your params definition, you have varphi__8.33, which should instead be something like varphi__X=8.33.

Solve has an alternative way of working with braces, with slightly different syntax. 

braces.mw

Get rid of =0.

 F-P-O-W.mw

Both methods work if you remove the "=0" on the pde. I always recommend this, for reasons I've given before.

restart

with(PDEtools)

with(LinearAlgebra)

NULL

with(SolveTools)

_local(gamma)

NULL

declare(u(x, y, z, w, t))

u(x, y, z, w, t)*`will now be displayed as`*u

declare(f(x, y, z, w, t))

f(x, y, z, w, t)*`will now be displayed as`*f

pde := 4*(diff(u(x, y, z, w, t), x, t))-(diff(u(x, y, z, w, t), `$`(x, 3), y))+diff(u(x, y, z, w, t), x, `$`(y, 3))+12*(diff(u(x, y, z, w, t), x))*(diff(u(x, y, z, w, t), y))+12*u(x, y, z, w, t)*(diff(u(x, y, z, w, t), x, y))-6*(diff(u(x, y, z, w, t), z, w))

4*(diff(diff(u(x, y, z, w, t), t), x))-(diff(diff(diff(diff(u(x, y, z, w, t), x), x), x), y))+diff(diff(diff(diff(u(x, y, z, w, t), x), y), y), y)+12*(diff(u(x, y, z, w, t), x))*(diff(u(x, y, z, w, t), y))+12*u(x, y, z, w, t)*(diff(diff(u(x, y, z, w, t), x), y))-6*(diff(diff(u(x, y, z, w, t), w), z))

oppde := [op(expand(pde))]; u_occurrences := map(proc (i) options operator, arrow; numelems(select(has, [op([op(i)])], u)) end proc, oppde); linear_op_indices := ListTools:-SearchAll(1, u_occurrences); pde_linear := add(oppde[[linear_op_indices]]); pde_nonlinear := expand(simplify(expand(pde)-pde_linear))

4*(diff(diff(u(x, y, z, w, t), t), x))-(diff(diff(diff(diff(u(x, y, z, w, t), x), x), x), y))+diff(diff(diff(diff(u(x, y, z, w, t), x), y), y), y)-6*(diff(diff(u(x, y, z, w, t), w), z))

12*(diff(u(x, y, z, w, t), x))*(diff(u(x, y, z, w, t), y))+12*u(x, y, z, w, t)*(diff(diff(u(x, y, z, w, t), x), y))

pde_linear, pde_nonlinear := selectremove(proc (term) options operator, arrow; not has((eval(term, u(x, y, z, w, t) = a*u(x, y, z, w, t)))/a, a) end proc, expand(pde))

4*(diff(diff(u(x, y, z, w, t), t), x))-(diff(diff(diff(diff(u(x, y, z, w, t), x), x), x), y))+diff(diff(diff(diff(u(x, y, z, w, t), x), y), y), y)-6*(diff(diff(u(x, y, z, w, t), w), z)), 12*(diff(u(x, y, z, w, t), x))*(diff(u(x, y, z, w, t), y))+12*u(x, y, z, w, t)*(diff(diff(u(x, y, z, w, t), x), y))

NULL

Download seperate_L-NL.mw

Well a lot depends on your objective, but here are some comments. 

(i) If the argument of RootOf is not a polynomial in _Z, then Maple has given up, and although you might be able to do some things with it, such as differentiate wrt a parameter, allvalues and convert radical won't do anything with it. I'm assuming remove_RootOf will put it back into unsolved form.

(ii) remove_RootOf just generates an implicit equation for which solve would give the RootOf solution; in some sense that is going backwards, but if you don't like RootOfs then it may be for you. On the other hand it is implicit, which you may not like.

(iii) If the argument of RootOf is a polynomial in _Z of degree n and it can be converted to radical form, then allvalues gives the n solutions in radical form. convert(..,radical) gives only the first of these; it is equivalent to convert(RootOf(..., index=1), radical).

(iv)  If the argument of RootOf is a polynomial in _Z of degree n and it can't be converted to radical form, which is the case for most high-degree polynomials, then convert(..,radical) won't do anything. allvalues will just return the n values still with RootOfs:

RootOf(..., index=1), RootOf(..., index=2), ... RootOf(..., index=n).

Here some code which should apply to any parametric curve. I tried to do it analytically, which works for the ellipse example, but in the general case will depend on the capabilities of solve.

restart

Curve in a parametric form (here an ellipse)

curve := proc (t) options operator, arrow; [2*sin(t), cos(t)] end proc

proc (t) options operator, arrow; [2*sin(t), cos(t)] end proc

pcurve := plot([curve(t)[], t = 0 .. 2*Pi], scaling = constrained, color = red)

procedure to plot tangent line at parameter value t.  y=y0 + m*(x-x0), [x0,y0] on curve

pT:=proc(t) local x0,y0,Dc,m,x;
x0,y0:=curve(t)[];
Dc:=D(curve)(t);
m:=Dc[2]/Dc[1];
plot(m*x+y0-m*x0,x,color=blue);
end proc:

Procedure to calculate curvature

C:=proc(t) local dx,dy,d2x,d2y;
dx,dy:=D(curve)(t)[];
d2x,d2y:=(D@@2)(curve)(t)[];
abs(dx*d2y-dy*d2x)/(dx^2+dy^2)^(3/2)
end proc:

Slope of tangent``(non-normalized tangent vector)

Dcurve := D(curve)

proc (z) options operator, arrow; [2*cos(z), -sin(z)] end proc

Find two points on curve with the same tangent slope and curvature

T1 := (D(curve))(t__1); T2 := (D(curve))(t__2); equalslopes := T1[1]*T2[2] = T1[2]*T2[1]

[2*cos(t__1), -sin(t__1)]

[2*cos(t__2), -sin(t__2)]

-2*cos(t__1)*sin(t__2) = -2*sin(t__1)*cos(t__2)

For t spaced multiples of Pi apart the slopes are the same

t2 := solve(equalslopes, t__2, allsolutions)

arctan(sin(t__1)/cos(t__1))+Pi*_Z1

simplify(t2); simplify(t2, symbolic)

arctan(tan(t__1))+Pi*_Z1

Pi*_Z1+t__1

And the curvatures are the same under this condition

C(.2); C(.2+Pi)``

.2615262308

.2615262308

And for the general case.

simplify(C(t)-C(t+Pi))

0

plots:-display(pcurve, pT(.2), pT(.2+Pi), view = [-2 .. 2, -2 .. 2])

NULL

Download Blaschke.mw

Generally, Maple works identically across platforms. The help page ?platform lists platform-specific issues, but only Mac OS has small differences from the other versions. I'm assuming by features you mean the capabilities of Maple itself. (For the GUI, the Java interface is also intended to be platform independent.) 

I would have said that s is already in factored form. Simplify is the correct way here, I think, though the answer appears to be 2^m not 2^(m+1). Maple's commands for working with polynomials and rational functions such as factor don't work for generic/unspecified exponents/degrees. Even if given a specific m, the default field for the coefficients is the rationals, so you will have to work more specifically on them to determine their factors, as I did here.

restart

Factored form

s := (1+sqrt(3))^(2*m+1)

(1+3^(1/2))^(2*m+1)

Example for m=6

s6 := eval(s, m = 6)

(1+3^(1/2))^13

Expanded form

e6 := expand(s6)

236224+136384*3^(1/2)

Extracting parts is ugly; then find gcd

op(1, e6), op([2, 1], e6); igcd(%); 2^6

236224, 136384

64

64

simplify(s/2^m)

(1+3^(1/2))*(2+3^(1/2))^m

NULL

Download test2.mw

 

Click on the green up-arrow in the Mapleprimes editor, click on choose file and browse to the file on your computer you want to upload and select it. Then click upload, and then click one of "insert link" or "insert contents" buttons. This definitely works for worksheet (*.mw) files. It doesn't work directly for *.mpl files, but if it contains only text then just rename it to *.txt and upload that. It works for some other types of files, but if it doesn't work then you can convert it to a .zip file and upload that.

Inserting contents of a worksheet sometimes fails to display the contents, but gives a link that works anyway.

Full evaluation is occuring in the first case, but not the second. If you change the second to eval(cat(x_,i-1));  it becomes the same as the first.

So in the first case, for i = 2, x_2 := x_1, but x_1 is already x_0, so you get x_2 := x_0.

I don't have Maple 2023, but for 2025 you need assumptions to get a result. I assumed everything positive, but you may have more specific requirements. For future reference. please upload a worksheet so we don't have to type in from the image.

Download Fourier.mw

plots:-complexplot([allvalues(RootOf(x^6 - 1))], style = point,
     symbol = solidcircle, color = red, symbolsize = 15, scaling = constrained);

The same result can be obtained with fsolve

plots:-complexplot([fsolve(x^6 - 1, complex)], style = point,
     symbol = solidcircle, color = red, symbolsize = 15, scaling = constrained);

allvalues(RootOf(x^6 - 1)) gives the symbolic solutions and  fsolve(x^6 - 1, complex) gives the numeric solutions.

Here's an example.

restart

with(plots); with(plottools)

display(polygon([[0, 0], [3, 4], [3, 1]], color = "Plasma 212"), polygon([[-1, 1], [-2, 4], [-5, 1]], color = red))

NULL

Download polygons.mw

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