acer

29759 Reputation

29 Badges

19 years, 316 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your phrasing is not entirely clear.

If by "...in terms of DC and T (and tau)" you mean that you you want some remaining variables expressed in terms of DC, T, and tau, then try the call,

   solve({eq || (1 .. 4)}, {toff, ton, x1, x2})

If you meant something else -- eg. solving for DC,T,tau -- then I think that the phrasing was off.

You only need to compute a Matrix Trace once, symbolically.

Once simplified, the resulting formula can be computed pretty quickly at your sampling points.

Also, it's more efficient to use seq than it is to repeatedly augment a list.

restart;

with(LinearAlgebra):

 

f := x -> exp(2*I*Pi*x):
S1 := (x, y) -> Matrix(3, 3, [[f(x - y), 0, 0], [0, 1, 0], [0, 0, f(-y)]]):
S2 := (x, y) -> Matrix(3, 3, [[f(y), 0, 0], [0, f(y - x), 0], [0, 0, 1]]):
C := 1/sqrt(3)*Matrix(3, 3, [[1, 1, 1], [1, f(1/3), f(2/3)], [1, f(2/3), f(1/3)]]):

d := Determinant(C . C);

-1

V := (x, y) -> (((S1(x, y)/d^(1/3)) . C) . (S2(x, y))) . C:

T:=unapply(simplify(evalc(Trace(V(x,y)))),x,y);

proc (x, y) options operator, arrow; (1/6)*(-I*3^(1/2)-1)*cos(2*Pi*(x-y))+(1/6)*(3*I+3^(1/2))*sin(2*Pi*(x-y))+(1/6)*(-I*3^(1/2)-1)*cos(2*Pi*y)+(1/6)*(3*I+3^(1/2))*sin(2*Pi*y)-((1/6)*I)*3^(1/2)+(1/3)*3^(1/2)*sin(2*Pi*x)+(1/3)*cos(2*Pi*x)+1/2 end proc

str := time[real]():
  tracevals:=[seq(seq(evalhf(T(0.01*i, 0.01*j)), i=1..100), j=1..100)]:
time[real]()-str;

0.29e-1

plots:-complexplot(tracevals, x = -2 .. 3, y = -3 .. 3);

plots:-display(
 plottools:-transform((x,y,z)->[x,y])(plot3d([Re(T(x,y)), Im(T(x,y)), 1],
                                             x = 0 .. 1, y = 0 .. 1)),
 view=[-3..3,-3..3]);

 

Andreas132_1.mw

Ok, I doubled up calls to T in the second plot, but you could even make that faster through memoization.

I suppose that there are other ways to get the 2D plot.

This is not terribly slow.

Check for correctness. This is a purely numeric approach. I didn't consider whether there is something smarter (eg. parametrization of the eigenvalues).

If the root-surfaces passed through each other (not happening here) then the coloring would still be by vertical position, rather than by surface.

restart;

with(LinearAlgebra):

f := x -> exp(2*I*Pi*x):

S1 := (x, y) -> Matrix(3, 3, [[f(x - y), 0, 0], [0, 1, 0], [0, 0, f(-y)]]):
S2 := (x, y) -> Matrix(3, 3, [[f(y), 0, 0], [0, f(y - x), 0], [0, 0, 1]]):

C := 1/sqrt(3)*Matrix(3, 3, [[1, 1, 1], [1, f(1/3), f(2/3)], [1, f(2/3), f(1/3)]]):

d := Determinant(C . C);

-1

V := (x, y) -> (((S1(x, y)/d^(1/3)) . C) . (S2(x, y))) . C:

M := simplify(V(x,y)):

bands := proc(x, y) option remember;
  if not [x,y]::list(numeric) then return 'procname'(args); end if;
  sort(simplify(fnormal(-I*ln~(Eigenvalues(evalf(eval(M,[':-x'=x,':-y'=y]))))),
                'zero'));
end proc:;

plot3d({bands(x,y)[1],bands(x,y)[2],bands(x,y)[3]}, x=0..1, y=0..1,
       color=[red,cyan,blue]);

Download eigenplotthing01.mw

The purpose of the special code about which your's asking is to have a call to procedure h return unevaluated (ie. as the same call, itself) in the case that both its arguments are not numeric.

Put briefly, it was done so that the call h(a,b) simply returns as itself, unevaluated, when a and b are merely unassigned, symbolic names rather than actual numeric values.

If h is not set up that way then the calls like h(a,b) -- that get invoked by the call BC2(a,b) -- would induce an error in dsolve/numeric.

Your call to implicitplot contains the call BC2(a,b) in the list that is passed as its first argument. That will get evaluated up-front -- in Maple's usual manner of handling calls to procedures/commands -- before implicitplot starts replacing the names a and b with actual numbers.

Below I show you that -- with your original variant -- the call BC2(a,b) returns with unevaluated calls like h(a,b) (ie. with a and b as symbolic names as its arguments).

Without the special code part of h (about which you're asking) that call BC2(a,b) would throw an error (because h(a,b) in turn would throw an error) before implicitplot even saw its arguments or had any opportunity to start replacing names a and b with actual numbers.

But first I'll show immediately below a variant in which that special construction of h is not needed. I get around the difficulties by using a so-called operator-form calling sequence to the implicitplot command. In this case implicitplot's argument consists of operators/procedures, and BC2 does not get called until its arguments are actually supplied by -- implicitplot's internals -- as numeric values.

restart;

 

ode := diff(y(x),x,x) + (y(x))^2*diff(y(x),x) + cos(y(x)) = x:

 

h:=proc(a,b)
  local F;
  Digits := 10;
    F:=dsolve({ode,y(0)=a,D(y)(0)=b},y(x),numeric);
    [rhs(F(1)[2]),rhs(F(1)[3])];
end proc:

 

BC1 := proc(a,b)
  (1 + a)*b - 3*a
end proc:
BC2 := proc(a,b)
  (1 + h(a,b)[1])*h(a,b)[2] - 3*h(a, b)[1] - h(a,b)[1]^2 + 0.5
end proc:

 

# This call produces an error.

h(a,b);

Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)

Error, (in F) parameter 'a' must be assigned a numeric value before obtaining a solution

#
# This call produces an error, because it calls h(a,b)
# which we just saw as throwing an error.
#
# But we can avoid using that call BC2(a,b) (with symbolic
# arguments `a` and `b`) by using an operator-form
# calling sequence in the first argument to `implicitplot`.
#

BC2(a,b);

Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)

Error, (in F) parameter 'a' must be assigned a numeric value before obtaining a solution

#
# In this variant we don't pass BC2(a,b) directly
# to implicitplot. Instead we wrap that in an operator.
#
# Notice that the 2nd and 3rd arguments are now pure ranges,
# and not a=range, b=range
#

plots:-implicitplot([(a,b)->BC1(a,b),(a,b)->BC2(a,b)], -5..1, -11..7,
  color=[black,red], legend=["BC1(a,b)=0","BC2(a,b)=0"], size=[300,300]);

#
# And now your original.
#
restart;

ode := diff(y(x),x,x) + (y(x))^2*diff(y(x),x) + cos(y(x)) = x:

h:=proc(a,b)
  local F;
  Digits := 10;
  if type(a,numeric) and type(b,numeric) then
    F:=dsolve({ode,y(0)=a,D(y)(0)=b},y(x),numeric);
    [rhs(F(1)[2]),rhs(F(1)[3])];
  else 'h'(a,b);
  end if;
end proc:

BC1 := proc(a,b)
  (1 + a)*b - 3*a
end proc:
BC2 := proc(a,b)
  (1 + h(a,b)[1])*h(a,b)[2] - 3*h(a, b)[1] - h(a,b)[1]^2 + 0.5
end proc:

#
# This call produces no error, since here a call to `h`
# is defined to return unevaluated when its arguments
# are not both numeric (eg. symbolic names).
#
# So we can use this expression directly in the first
# argument passed to implicitplot.
#

BC2(a,b);

(1+h(a, b)[1])*h(a, b)[2]-3*h(a, b)[1]-h(a, b)[1]^2+.5

plots:-implicitplot([BC1(a,b),BC2(a,b)], a=-5..1, b=-11..7,
  color=[black,red], legend=["BC1(a,b)=0","BC2(a,b)=0"], size=[300,300]);

Download Mikey_01.mw

The following attachment is as much as I believe can be recovered from your zipped .bak file.

STAT_131_Introduction_to_Prob_acc.mw

There might be two missing (unrecoverable) Inputs, in section "Day 14", between the line with "bivariate random vector" and the line with "Joint distribution functions".

I suggest that you upgrade to Maple 2023, if available to you. It seems to have fewer incidences of this kind of problem.

You can make the animation from your original "Test" collection, by passing the extra option insequence to your call to the plots:-display command.

Or you can account for the fact that plots:-animate passes a float value for i, by turning that into an integer prior to the indexing into your Matrix data.

Note. By default animate uses 25 frames. You could also supply the option frames=18 if you want animate to generate exactly 18 frames for i=1..18. That would make the two approaches produce the same animation. But it'd still pass i as a float, so you'd still need to trunc/floor/etc to get an integer. This option also provides an easy way to slow it down -- ie. duplicating frames by using a higher frames value, eg. multiples of 18 here, say.

restart

with(plottools, line); with(plots)

Trvl := Matrix(5, 18, {(1, 1) = 0, (1, 2) = 1, (1, 3) = 2, (1, 4) = 3, (1, 5) = 4, (1, 6) = 5, (1, 7) = 6, (1, 8) = 7, (1, 9) = 8, (1, 10) = 9, (1, 11) = 10, (1, 12) = 11, (1, 13) = 12, (1, 14) = 13, (1, 15) = 14, (1, 16) = 15, (1, 17) = 16, (1, 18) = 17, (2, 1) = 25.00000000, (2, 2) = 25.62348980, (2, 3) = 26.24697960, (2, 4) = 26.87046941, (2, 5) = 27.49395921, (2, 6) = 28.11744901, (2, 7) = 28.81795052, (2, 8) = 29.70796779, (2, 9) = 30.69482490, (2, 10) = 31.66997559, (2, 11) = 32.64189447, (2, 12) = 33.63901734, (2, 13) = 34.59934793, (2, 14) = 35.46317753, (2, 15) = 36.17679740, (2, 16) = 36.69583812, (2, 17) = 36.98802824, (2, 18) = 37.03520080, (3, 1) = 9.50000000, (3, 2) = 10.28183148, (3, 3) = 11.06366296, (3, 4) = 11.84549445, (3, 5) = 12.62732593, (3, 6) = 13.40915741, (3, 7) = 14.11748988, (3, 8) = 14.56318511, (3, 9) = 14.69313898, (3, 10) = 14.49329251, (3, 11) = 14.26929209, (3, 12) = 14.29271187, (3, 13) = 14.56209574, (3, 14) = 15.06069470, (3, 15) = 15.75750830, (3, 16) = 16.60921202, (3, 17) = 17.56285107, (3, 18) = 18.55913279, (4, 1) = 26.55872458, (4, 2) = 27.18221431, (4, 3) = 27.80570411, (4, 4) = 28.44091912, (4, 5) = 29.26771501, (4, 6) = 30.27132826, (4, 7) = 31.26754127, (4, 8) = 32.19797655, (4, 9) = 33.15526524, (4, 10) = 34.16855668, (4, 11) = 35.08363639, (4, 12) = 35.87210441, (4, 13) = 36.48493760, (4, 14) = 36.88403298, (4, 15) = 37.04457671, (4, 16) = 36.95658698, (4, 17) = 36.62553455, (4, 18) = 36.06730316, (5, 1) = 11.45457880, (5, 2) = 12.23641019, (5, 3) = 13.01824167, (5, 4) = 13.79066482, (5, 5) = 14.38908368, (5, 6) = 14.67833203, (5, 7) = 14.61699479, (5, 8) = 14.33989949, (5, 9) = 14.25015666, (5, 10) = 14.40907532, (5, 11) = 14.80585186, (5, 12) = 15.41668792, (5, 13) = 16.20360467, (5, 14) = 17.11767545, (5, 15) = 18.10206776, (5, 16) = 19.09557685, (5, 17) = 20.03643114, (5, 18) = 20.86416514})

display(seq(line([Trvl[2, i], Trvl[3, i]], [Trvl[4, i], Trvl[5, i]], color = green), i = 1 .. 18), insequence)

animate(proc (i) options operator, arrow; line([Trvl[2, i], Trvl[3, i]], [Trvl[4, i], Trvl[5, i]], color = green) end proc, [trunc(i)], i = 1 .. 18)

NULL

Download 23-11-03_Q_Animate_a_line_ac.mw

It's clear from your Questions picture, and the attachment's filename, that you are trying to Read an image stored in your Maple workbook.

With a short edit to your this URI the following zipped workbook succeeds for me using Maple 2023.1.

TestTrans_ac.zip

The following is as much as I believe can be recovered here. (Three input equations were corrupted; somewhat near the beginning.)

Hjemmeopgave_7_igen_ac.zip

I suggest that you upgrade to Maple 2023, if available to you. It seems to have fewer incidences of this problem.

You can use your desired ranges for x and t in the calls to contourplot, along with scaling by Mx and N respectively. And you can also use the desired ranges directly in the (density-plot) PLOT call.

 

restart;

 

Digits := 20:

 

with(plots): with(CurveFitting,ArrayInterpolation):
 

 

N := 20: Mx := 20: L := 1: `&Delta:x` := L/Mx: T := 2: `&Delta:t` := T/N:

 

for i from 0 while i <= Mx do u[i, 0] := 0 end do:
for n from 0 while n <= N do u[0, n] := 0: u[Mx, n] := 0 end do:
for n from 0 while n <= N-1 do
  for i while i <= Mx-1 do
    Ru[i, n] := eval((u[i, n+1]-u[i, n])/`&Delta:t` = (u[i+1, n+1]-2*u[i, n+1]+u[i-1, n+1])/`&Delta:x`^2-u[i, n+1]+.5);
  end do;
  Sol[n] := fsolve({seq(Ru[i, n], i = 1 .. Mx-1)});
  assign(op(Sol[n]));
end do:
 

 

Digits := 10: NP := 100:
XX := [seq(seq(i1/Mx, i1 = 0 .. Mx), i2 = 0 .. N)]:
TT := [seq(seq(i2, i1 = 0 .. Mx), i2 = 0 .. N)]:
ZZ := [seq(seq(u[i1, i2], i2 = 0 .. N), i1 = 0 .. Mx)]:

 

interfunc := subs(__M = Matrix(Matrix(Mx+1, N+1, ZZ), datatype = float[8]),
  (x, y) -> ArrayInterpolation([[`$`(i1, i1 = 0 .. Mx)], [`$`(i2, i2 = 0 .. N)]],
                               __M, [[x], [y]], method = cubic)[1, 1]):

 

newz := ArrayInterpolation([[`$`(i1, i1 = 0 .. Mx)], [`$`(i2, i2 = 0 .. N)]],
                           Matrix(Mx+1, N+1, ZZ, datatype = float[8]),
                           [[seq(Mx*(i3-1)/(NP-1), i3 = 1 .. NP)],
                            [seq(N*(i3-1)/(NP-1), i3 = 1 .. NP)]], method = cubic):

 

nminz, nmaxz := (simplify@fnormal@min, max)(newz):

 

C := .666*(1-ImageTools:-FitIntensity(newz)):

 

PC := PLOT(GRID(0 .. 2, 0 .. 2, newz, COLOR(HUE, C)), STYLE(PATCHNOGRID)):

 

numcontours := 15:

 

PP := display(PC,
   contourplot((x,t)->interfunc(Mx/2*x,N/2*t), 0 .. 2, 0 .. 2, grid=[101,101],
               thickness = 0, contours = [seq(nminz+(nmaxz-nminz)*(i3-1)/(numcontours+2-1),
                                              i3 = 1 .. numcontours+1)]),
   seq(plot(ZZ[1], nminz .. nminz, thickness = 15, color = COLOR(HUE, .666*(1-i3/(numcontours+1))),
   legend = sprintf(" %.3f", nminz+i3*(nmaxz-nminz)/(numcontours+1))), i3 = numcontours+1 .. 0, -1),
   legendstyle = [location = right, font = [Helvetica, 14]], font = [Helvetica, 16],
   labelfont = [Helvetica, bold, 16], labels = [x, t], labeldirections = [horizontal, vertical]):
 

 

display(PP, size = [500, 400]);

 

 

display(subs(THICKNESS(0)=THICKNESS(0.5),
             THICKNESS(15)=THICKNESS(35),PP), size = [720, 640]);

 


I also made a few changes for (IMO) a better look, such as getting rid of the minus sign on "-0.000", increasing the contourplot grid, etc.

Also, one way to get a nicer final export is to increase the plot size, since you can then scale down using a good external image processing program. I also made the contours thinner using subs, since IIRC Maple 2015's contourplot didn't allow that thickness (thinner than thickness=0 !) 

This direct approach can be more efficient than using plottools:-transform to re-scale/shift the original result (after the fact).

I think that it's often easier to manage in the long run if your calls/functions are properly scaled up front, instead of fudging the tickmarks later on. (I choose forced tickmarks only as last resort, usually. It doesn't work with all later transformations, as one reason.)

By the way, I suggest exporting the plot from Maple in .PNG format. Well, almost anything except .JPG, for which the results are generally poor.

If you want advice about exporting the data then you should describe the required format in explicit and adequate detail. Merely mentioning a product's name, like "tecplot", is not adequate.

ps. Quite a bit of this code looks like bits that I'd written. Is that right? I'm curious now; where did you get it from?

Since you gave a followup example (elsewhere),
 

with(Statistics):

L1:=[2,4,6]:

ColumnGraph(L1,
            axis[1]=[tickmarks=[[.4="abe",1.4="banan",2.4="palme"],
                     rotation=Pi/4]]);

Download jestrup1.mw

This is as much as I could recover. I think it is most of it.

I left all the sections unexpanded.

prac_exam_ece4179_acc.mw

There may be a missing equation just after the line with "evaluate for the given points" in section 1, and another just after "This decision boundary will realize" in section 4.

I notice that you were using Maple 2022.2.  I suggest upgrading to Maple 2023 if available to you; it seems to have fewer occurences of this problem.

Your attempts at forming a Matrix try to use Ans[k], but your loop simply assigns (repeatedly) to just Ans. It looks like you meant to assign to Ans[j] and Ans1[j] in the loop.

In your systems of equations you have terms like Theta(eta,t), but in your attempts at forming a Matrix you have the arguments of Theta reversed, like Theta(0.5,eta). Did you mean Theta(eta,0.5) instead? The same happens for the other functions.

When you write,
   eval(diff(Theta(0.5,eta),eta),Ans[k])(0)
are you wanting instead to take from Ans[k] the derivative of Theta(eta,0.5) w.r.t. eta, and then evaluate that very close to eta=0? If so then this is essentially the same as your query in your previous Question. You are mistakenly using technique appropriate for a result from dsolve(...,numeric) rather than from pdsolve(...,numeric). Have a look at this: error_in_table_value_ac.mw

You could avoid duplication of conputation by computing the Matrix entries (involving the other terms that I omitted) in a loop.

Are you trying to get something like the following?

restart

randomize()

M := proc () local A, B, operation, str; A := RandomTools:-Generate(integer(range = -5 .. 5, exclude = {0})); B := RandomTools:-Generate(integer(range = -5 .. 5, exclude = {0, A})); operation := combinat:-randcomb([`%+`, `%-`, `%*`], 1)[]; str := sprintf("%a(%a,%a)", operation, A, B); InertForm:-Display(InertForm:-Parse(str), 'inert' = false) = value(operation(A, B)) end proc

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

M()

0, "%1 is not a command in the %2 package", _Hold, Typesetting

Download Qop2_ac.mw

Those are actually equations, and you could use or access their lhs and rhs separately.

Note that formation of the string may not be strictly necessary, compared with simply calling the operation on the arguments directly to get the inert expression. (But there seemed to be a few corner cases, where using the inert operators with prefix form helped.) Did you really need the string representation, using infix form, or is the above result from InertForm:-Display enough?

I notice that you had B set up to avoid being A. Is that because you didn't want A-B to produce 0? If so perhaps you'd also want to avoid A+B=0 when B=-A? And perhaps you'd prefer neither A nor B to be -1 or 1 when multiplying?  Qop2_ac2.mw

It sounds as if your preferences were not migrated to your new installation. (There's usually a dialogue that asks about that, during installation.)

You can set the preference by using the main menubar,

   Tools->Options->Display

and then set the drop-menu box "Input display" to "Maple Notation".  Then press the "Apply Globally" button to set it as default.

@zenterix You could use the terser,

   m::{Matrix,list(Matrix)}

instead of using `Or` in the type specification.

First 7 8 9 10 11 12 13 Last Page 9 of 309