Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Find x182 given that

 

x0=2.25

x1=1.75

xn= (1/6)*(sqrt(4+x(n-1))/(x(n-2))

 

and enter your answer correct to 10 significant figures in the box below.

To check that your calculations are correct, you should be able to calculate that  x93 is approximately 0.1348891.

[Note that you should do your calculations correct to 10 significant figures. Use ]

 

     x182=    Preview Change entry mode  

The terms of a sequence an are generated by the recurrence relation

a(n+1)=a(n)−2a(n−1)+a(n−2) for n=3,4,5,...

 

Using your Maple worksheet, write a for loop to find the value of a50 given that

a1=2,a2=-1 and a3=0

 

Copy (Ctrl-C) the correct value of a50 from your Maple worksheet and paste (Crtl-V) it in th answer box.

Preview Change entry mode 

 

 

Hi

When I try to substitute a value for j, it doesn't evaluate.

add.mw

Hi, I'm having trouble setting up a procedure for an assignment, we're trying to find root mean square error and remove variable by variable to find the best line of fit etc etc... hopefully from the coding you can see what I'm am trying to do, but I don't understand why it is not working? I wonder if it has something to do with the X and Y being read in?
 
M:=readdata("C:\\Users\\bjense04.CSUMAIN.001\\Documents\\ass1Q2.txt",[float,float,float,float,float]):
convert(M,matrix):
with(LinearAlgebra):
n:=RowDimension(convert(M,matrix));
X:=convert(M[1..n,1..4],matrix):
Y:=convert(M[1..n,5..5],vector):
with(Statistics):
FullEQN:=LinearFit([1,a,b,c,d],X,Y,[a,b,c,d]);
#the next part is incomplete
rmse_mlr:=proc(Full)
local i, sq, n, predicted;
sq:=0:
for i from 1 to n do
 predicted:=subs([a=X[i,1],b=X[i,2],c=X[i,3],d=X[i,4]],Full);
 sq:=sq+(Y[i]-predicted)^2;
end do:
return sqrt(sq/n);
end proc;
 
 
I then test the procedure with 
rmse_mlr(FullEQN,X,Y);
 
and the response i get is

Error, (in rmse_mlr) final value in for loop must be numeric or character
 
help?

Is it possible in Maple to add new type, and assign initial/default value that the variable of that type will take on?

I can't figure if this is possible or not and if it, what is the correct syntax. This is something very common in strong typed Language such as Ada for example.

For example, in Ada one can create new type wiith default value like this

              type My_Float is digits 20   with Default_Value => 0.5;

Later on, when declaring variable of the above type, if no explicit value is given then, then the variable will have the value 0.5

             A: My_float;

Or one can override the default value:

             A: My_float := 0.1;

I am trying to do the same with Maple using that handle in AddType(typename, handler)

But no success. Here is an example

restart;
TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t>0 and t<150));
p::age_type:=20;

Now, I want to change the above to tell TypeTool to have default value as say 30. So when I do 

             p::age_type;

Then the variable p will have value of 30 automatically.

Is this possible in Maple? 

Update

After a little bit of trying things, I came up with this. May be not prefect, but does what I want for now.

The idea is to make the initialization of the variable, as a proc() which takes in default values. I plan to use this for record types, so this example below is meant for this use, but the idea is the same for other types.

restart;
kernelopts('assertlevel'=2):
TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t<150));
TypeTools:-AddType(name_type,t->evalb(t::string and StringTools:-Length(t)<100));
TypeTools:-AddType(person_type,record(age::age_type,name::name_type));
make_person_type:=proc({the_age::age_type:=30, the_name::name_type:="joe doe"},$)::person_type;
   local p::person_type;
   p:=Record('age'=the_age,'name'=the_name);
   return p
end proc;

 

And now one can make a variable of new type, which takes in default values like this

       p::person_type:=make_person_type()

which returns 

              p := Record(age = 30, name = "joe doe")

And to set specific initial values:

     p::person_type:=make_person_record(the_age=35);

Which returns

            p := Record(age = 35, name = "joe doe")

It would have been better is Maple allows one to set the default value for type when it is defined, so everything is in one place and there would have been no need to make an explicit proc() for to set the initial value of the variable.

Does anyone know why pdetest is not giving [0, 0, 0] for the solution of pdsolve?
 

restart

eq := diff(u(x, t), t)-k*(diff(u(x, t), x, x)) = 0

diff(u(x, t), t)-k*(diff(diff(u(x, t), x), x)) = 0

(1)

ic := u(x, 0) = g(x)

u(x, 0) = g(x)

(2)

bc := (D[1](u))(0, t) = 0, eval(diff(u(x, t), x)+u(x, t), x = 1) = 0

(D[1](u))(0, t) = 0, eval(diff(u(x, t), x), {x = 1})+u(1, t) = 0

(3)

sol := `assuming`([simplify(pdsolve([eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

u(x, t) = `casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And((sin(lambda[n])*lambda[n]-cos(lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})

(4)

`assuming`([simplify(pdetest(sol, [eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

[-(diff(diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), x))*k+diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), t), `casesplit/ans`(Sum(4*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})-g(x), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 0}), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 1})+`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n])*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})]

(5)

``


 

Download PDE.mw

inside my module, I create types to be used by only procs, and other sub modules inside the main one package I have.

but TypeTools:-AddType invoked inside my package, adds the type to system. So a user after loading the package can still see it and use this type.

Adding local before TypeTools:-AddType is not supported.

How to make the type only visible inside the package? Here is example

restart;
kernelopts('assertlevel'=2):
my_pkg:=module()
 option package;
 TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t<150));
 export foo:=proc()
    local age::age_type:=20;
    print("age=",age);
 end proc;
end module;

with(my_pkg);

And now a user can do this

x::age_type:=30;

It worked, since age_type is now in the system. This can also cause a problem, since loading this package, could overwrite a type name allready set there by another package the user happened to load before.

If I can make it at least such that the user has to do 

x::my_pkg:-age_type:=200;

That would be better. But the best solution is to make the type name completely not visible from outside the package. i.e. private type to the package only.

I looked at Extension Mechanisms under typetools in help, but do not see how to use that for what I want.

 

Maple 2020.1

f[2](x) = -(3*R^2*x^11)/30800 + R^2*x^9/420 - (177*R^2*x^7)/9800 + M1*M2*x^5/40 + (17*R^2*x^5)/700 + ((-(3*M1*M2)/10 - (443*R^2)/21560)*x^3)/6 + (M1*M2/40 - (137*R^2)/26950)*x

Hi,

I am writing the following code and MAPLE is giving me operator error. Please help (file: doubt_6.mw)

d2:=100000000

for m in set_m do
    for n in set_n do
        SOL1 := fsolve({ODE11, ODE12}, {N, t__2});
        N1:=eval(N,SOL1);
        t_2_1 :=eval(t__2,SOL1);
        T_1:= eval(T, [lambda = 3, a = 300, b = .15, c = .25, A__m = 300, A__d = 150, A__r = 50,C__m = 4, P__m = 8, P__d = 10, 
        P__r = 12, theta__m = .15, theta__d = .12, theta__r = 0.5e-1, h__m = .2, h__d = .3, h__r = .5, i__m = .1, i__d = .1, 
        i__r = .1, i__om = .1, i__OD = .15, i__c = .3, i__e = .2, M = 2, alpha = 0.2e-1, t__2 = t_2_1]):
        t_31:= T_1 /m ;
        t_41:= T_1 /(m*n) ;
        if (N1<=t_41 and 2>=t_31) then
            d1:= eval(TCS__1, [lambda = 3, a = 300, b = .15, c = .25, A__m = 300, A__d = 150, A__r = 50, C__m = 4, P__m = 8, 
            P__d = 10, P__r = 12, theta__m = .15, theta__d = .12, theta__r = 0.5e-1, h__m = .2, h__d = .3, h__r = .5, i__m = .1, 
            i__d = .1, i__r = .1, i__om = .1, i__OD = .15, i__c = .3, i__e = .2, M = 2, alpha = 0.2e-1, t__2=t_2_1, N=N1]):
            if (d1<= d2) then
                d2:= d1;
                print("Value is updated",d2,N1,t_2_1,"for",m,n)
            end if
        end if    
        print(N1,t_2_1,t_31,t_41,d1,m,n)
    end do
end do

 

Thanks in advance

Any idea why Maple can simplify this expression only when multiplied by -1 but not otherwise?

expr:=sqrt(-2 + 2*I*sqrt(3));
simplify(expr)

But now

simplify(-1*expr)

Multiplying by -1 should not have mattered. Becuase -2 + 2*I*sqrt(3)=(1+I*sqrt(3))^2  Therefore sqrt(-2 + 2*I*sqrt(3)) is the same as 1+I*sqrt(3) and Maple knows this:

simplify((1 + sqrt(3)*I)-expr) gives zero.

But Maple only simplifies -expr  and not +expr.

Just wondering is someone can suggest why that is and if this is considered OK?

Maple 2020.1, Physics 724

Hello

I need to check if the solution (sols) of a (nonlinear) polynomial system of equations (the coefficients are not numeric) has only one solution for, let's say, y and (one solution for y and one solution for z).  I cannot use allvalues (not threadsafe according to CodeTools:-ThreadSafetyCheck) and then count the number of solutions. 

I have removed all solutions that fit the command 

ormap(x->x=true,map(has,rhs~(op~(sols)),_Z))

(RootOf works too).  (Please tell me if I am using ormap correctly).  

Even using the above command and then checking if nops(sols)=1, not all one solutions are caught.  

Many thanks

Ed

 

 

 

 

Any idea what this could mean?

I'm comparing 2 matrices where one of them is empty, and the other one is unitfree.

Hello,

I want to ask, I have a system of equations... 

eq1:=K_1=(((n_Cl-x)*u_Cl)*(n_H*u_H))/(n_HCl*m);
eq2:=K_2=(((n_Na-x)*u_Na)*(n_OH*u_OH))/(n_NaOH*m);
eq3:=K_w=(n_H*u_H/m)*(n_OH*u_OH/m);
eq4:=K_NaCl=((n_Na-x)*u_Na*(n_Cl-x)*u_Cl)/m^2;
eq5:=(n_NaCl-x)=(n_Na-x)+n_NaOH;
eq6:=(n_NaCl-x)=(n_Cl-x)+n_HCl;
eq7:=(n_Na-x)+n_H=(n_Cl-x)+n_OH;
eq8:=2*ionic=(n_H/m)+((n_Cl-x)/m)+((n_Na-x)/m)+(n_OH/m);
eq9:=u_H=0.4077*ionic^2-0.3152*ionic+0.9213;
eq10:=u_Na=0.0615*ionic^2-0.2196*ionic+0.8627;
eq11:=u_OH=0.1948*ionic^2-0.1803*ionic+0.8887;
eq12:=m=r*V;
eq13:=u_Cl=(1.417625986641341e-01)*exp^(-ionic/2.199955601666953e-02)+2.369460669647978e-01*exp^(-ionic/3.756472377688394e-01)+5.859738096037875e-01;

but when I use solve command, Maple starts computing, but suddenly gives message: Solutions may have been lost. 

I guess problem is the last exponential equation. Is there any way how to make Maple to be able to compute this system?

 

             

A lot of scientific software propose packages enabling drawing figures in XKCD style/
Up to now I thought this was restricted to open products (R, Python, ...) but I recently discovered Matlab and even Mathematica were doing same.

Layton S (2012). “XKCDIFY! Adding flair to boring Matlab Axes one plot at a time.” Last accessed on December 08, 2014, URL https://github.com/slayton/matlab-xkcdify.

Woods S (2012). “xkcd-style graphs.” Last accessed on December 08, 2014, URL http://mathematica.stackexchange.com/questions/11350/xkcd-style-graphs/ 11355#11355.

 

So why not Maple?

As a regular user of R, I could have visualize the body of the corresponding procedures to see how these drawings were made and just translate theminto Maple.
But copying for the sake of copying is not of much interest.
So I started to develop some primitives for "XKCD-drawing" lines, polygons, circles and even histograms.
My goal is not to write an XKCD package (I don't have the skills for that) but just to arouse the interest of (maybe) a few people here who could continue this preliminary work


A main problem is the one of the XKCD fonts: no question to redefine them in Maple and I guess using them in a commercial code is not legal (?). So no XKCD font in this first work, nor even the funny guy who appears recurently on the drawings (but it could be easily constructed in Maple).

In a recent post (Plot styling - experimenting with Maple's plotting...) Samir Khan proposed a few styles made of several plotting options,  some of which he named "Excel style" or "Oscilloscope style"... maybe a future "XKCD xtyle" in Maple ?


This work has been done with Maple 2015 and reuses an old version of a 1D-Kriging procedure 

 

restart:

with(LinearAlgebra):
with(plots):
with(Statistics):

 

The principle is always the same:
    1/   Let L a straight line which is either defined by its two ending points (xkvd_hline) or taken as the default [0, 0], [1, 0] line.
          For xkvd_hline the given line L is firstly rotate to be aligned with the horizontal axis.

    2/   Let P1, ..., PN N points on L. Each Pn writes [xn, yn]

    3/   A random perturbation rn is added yo the values y1, ..., yN

    4/   A stationnary random process RP, with gaussian correlation function is used to build a smooth curve passing through the points
          (x1, y1+r1), ..., (xN, yN+rN) (procedure KG where "KG" stands for "Kriging")

    5/   The result is drawn or mapped to some predefined shape :
                  xkcd_hist,
                  xkcd_polyline,
                  xkcd_circle

    6/   A procedure xkcd_func is also provided to draw functions defined by an explicit relation.
 

KG := proc(X, Y, psi, sigma)
  local NX, DX, K, mu, k, y:
  NX := numelems(X);
  DX := < seq(Vector[row](NX, X), k=1..NX) >^+:
  K  := (sigma, psi) -> evalf( sigma^2 *~ exp~(-((DX - DX^+) /~ psi)^~2) ):
  mu := add(Y) / NX;
  k  := (x, sigma, psi) -> evalf( convert(sigma^2 *~ exp~(-((x -~ X ) /~ psi)^~2), Vector[row]) ):
  y  := mu + k(x, sigma, psi) . (K(sigma, psi))^(-1) . convert((Y -~ mu), Vector[column]):
  return y
end proc:


xkcd_hline := proc(p1::list, p2::list, a::nonnegative, lc::positive, col)
  # p1 : first ending point
  # p2 : second ending point
  # a  : amplitude of the random perturbations
  # lc : correlation length
  # col: color
  local roll, NX, LX, X, Z:
  roll := rand(-1.0 .. 1.0):
  NX   := 10:
  LX   := p2[1]-p1[1]:
  X    := [seq(p1[1]..p2[1], LX/(NX-1))]:
  Z    := [p1[2], seq(p1[2]+a*roll(), k=1..NX-1)]:
  return plot(KG(X, Z, lc*LX, 1), x=min(X)..max(X), color=col, scaling=constrained):
end proc:


xkcd_line := proc(L::list, a::nonnegative, lc::positive, col, {lsty::integer:=1})
  # L  : list which contains the two ending point
  # a  : amplitude of the random perturbations
  # lc : correlation length
  # col: color
  local T, roll, NX, DX, DY, LX, A, m, M, X, Z, P:
  T    := (a, x0, y0, l) ->
             plottools:-transform(
               (x,y) -> [ x0 + l * (x*cos(a)-y*sin(a)), y0 + l * (x*sin(a)+y*cos(a)) ]
             ):
  roll := rand(-1.0 .. 1.0):
  NX   := 5:
  DX   := L[2][1]-L[1][1]:
  DY   := L[2][2]-L[1][2]:
  LX := sqrt(DX^2+DY^2):
  if DX <> 0 then
     A := arcsin(DY/LX):
  else
     A:= Pi/2:
  end if:
  X := [seq(0..1, 1/(NX-1))]:
  Z := [ seq(a*roll(), k=1..NX)]:
  P := plot(KG(X, Z, lc, 1), x=0..1, color=col, scaling=constrained, linestyle=lsty):
  return T(A, op(L[1]), LX)(P)
end proc:


xkcd_func := proc(f, r::list, NX::posint, a::positive, lc::positive, col)
  # f  : function to draw
  # r  : plot range
  # NX : number of equidistant "nodes" in the range r (boundaries included)
  # a  : amplitude of the random perturbations
  # lc : correlation length
  # col: color
  local roll, F, LX, Pf, Xf, Zf:
  roll := rand(-1.0 .. 1.0):
  F    := unapply(f, indets(f, name)[1]);
  LX   := r[2]-r[1]:
  Pf   := [seq(r[1]..r[2], LX/(NX-1))]:
  Xf   := Pf +~ [seq(a*roll(), k=1..numelems(Pf))]:
  Zf   := F~(Pf) +~ [seq(a*roll(), k=1..numelems(Pf))]:
  return plot(KG(Xf, Zf, lc*LX, 1), x=min(Xf)..max(Xf), color=col):
end proc:




xkcd_hist := proc(H, ah, av, ax, ay, lch, lcv, lcx, lcy, colh, colxy)
  # H   : Histogram
  # ah  : amplitude of the random perturbations on the horizontal boundaries of the bins
  # av  : amplitude of the random perturbations on the vertical boundaries of the bins
  # ax  : amplitude of the random perturbations on the horizontal axis
  # ay  : amplitude of the random perturbations on the vertical axis
  # lch : correlation length on the horizontal boundaries of the bins
  # lcv : correlation length on the vertical boundaries of the bins
  # lcx : correlation length on the horizontal axis
  # lcy : correlation length on the vertical axis
  # colh: color of the histogram
  # col : color of the axes
  local data, horiz, verti, horizontal_lines, vertical_lines, po, rpo, p1, p2:
  data  := op(1..-2, op(1, H)):
  verti := sort( [seq(data[n][3..4][], n=1..numelems([data]))] , key=(x->x[1]) );
  verti := verti[1],
           map(
                n -> if verti[n][2] > verti[n+1][2] then
                        verti[n]
                      else
                        verti[n+1]
                      end if,
                [seq(2..numelems(verti)-2,2)]
           )[],
           verti[-1];
  horiz := seq(data[n][[4, 3]], n=1..numelems([data])):

  horizontal_lines := NULL:
  for po in horiz do
    horizontal_lines := horizontal_lines, xkcd_hline(po[1], po[2], ah, lch, colh):
  end do:

  vertical_lines := NULL:
  for po in [verti] do
    rpo := po[[2, 1]]:
    vertical_lines := vertical_lines, xkcd_hline([0, rpo[2]], rpo, av, lcv, colh):
  end do:

  p1 := [2*verti[1][1]-verti[2][1], 0]:
  p2 := [2*verti[-1][1]-verti[-2][1], 0]:

  return
    display(
      horizontal_lines,
      T~([vertical_lines]),
      xkcd_hline(p1, p2, ax, lcx, colxy),
      T(xkcd_hline([0, 0], [1.2*max(op~(2, [verti])), 0], ay, lcy, colxy)),
      axes=none,
      scaling=unconstrained
    );
end proc:


xkcd_polyline := proc(L::list, a::nonnegative, lc::positive, col)
  # xkcd_polyline reduces to xkcd_line whebn L has 2 elements
  # L  : List of points
  # a  : amplitude of the random perturbations
  # lc : correlation length
  # col: color
  local T, roll, NX, n, DX, DY, LX, A, m, M, X, Z, P:
  T    := (a, x0, y0, l) ->
             plottools:-transform(
               (x,y) -> [ x0 + l * (x*cos(a)-y*sin(a)), y0 + l * (x*sin(a)+y*cos(a)) ]
             ):
  roll := rand(-1.0 .. 1.0):
  NX   := 5:
  for n from 1 to numelems(L)-1 do
    DX   := L[n+1][1]-L[n][1]:
    DY   := L[n+1][2]-L[n][2]:
    LX := sqrt(DX^2+DY^2):
    if DX <> 0 then
      A := evalf(arcsin(abs(DY)/LX)):
      if DX >= 0 and DY <= 0 then A := -A end if:
      if DX <= 0 and DY >  0 then A := Pi-A end if:
      if DX <= 0 and DY <= 0 then A := Pi+A end if:
    else
      A:= Pi/2:
      if DY < 0 then A := 3*Pi/2 end if:
    end if:
    if n=1 then
      X := [seq(0..1, 1/(NX-1))]:
      Z := [seq(a*roll(), k=1..NX)]:
    else
      X := [0    , seq(1/(NX-1)..1, 1/(NX-1))]:
      Z := [Z[NX], seq(a*roll(), k=1..NX-1)]:
    end if:
    P    := plot(KG(X, Z, lc, 1), x=0..1, color=col, scaling=constrained):
    P||n := T(A, op(L[n]), LX)(P):
  end do;
  return seq(P||n, n=1..numelems(L)-1)
end proc:


xkcd_circle := proc(a::nonnegative, lc::positive, r::positive, cent::list, col)
  # a   : amplitude of the random perturbations
  # lc  : correlation length
  # r   : redius of the circle
  # cent: center of the circle
  # col : color
  local roll, NX, LX, X, Z, xkg, A:
  roll := rand(-1.0 .. 1.0):
  NX   := 10:
  X    := [seq(0..1, 1/(NX-1))]:
  Z    := [0, seq(a*roll(), k=1..NX-1)]:
  xkg  := KG(X, Z, lc, 1):
  A    := Pi*roll():
  return plot([cent[1]+r*(1+xkg)*cos(2*Pi*x+A), cent[2]+r*(1+xkg)*sin(2*Pi*x+A), x=0..1], color=col)
end proc:

T := plottools:-transform((x,y) -> [y, x]):
 

# Axes plot

x_axis := xkcd_hline([0, 0], [10, 0], 0.03, 0.5, black):
y_axis := xkcd_hline([0, 0], [10, 0], 0.03, 0.5, black):
display(
  x_axis,
  T(y_axis),
  axes=none,
  scaling=constrained
)

 

# A simple function

f := 1+10*(x/5-1)^2:
F := xkcd_func(f, [0.5, 9.5], 6, 0.3, 0.4, red):

display(
  x_axis,
  T(y_axis),
  F,
  axes=none,
  scaling=constrained
)

 

# An histogram

S := Sample(Normal(0,1),100):
H := Histogram(S, maxbins=6):
xkcd_hist(H,   0, 0.02, 0.001, 0.01,   1, 0.1, 0.01, 1,   red, black)

 

# Axes plus grid with two red straight lines

r := rand(-0.1 .. 0.1):

x_axis := xkcd_line([[-2, 0], [10, 0]], 0.01, 0.2, black):
y_axis := xkcd_line([[0, -2], [0, 10]], 0.01, 0.2, black):
d1     := xkcd_line([[-1, 1], [9, 9]] , 0.01, 0.2, red):
d2     := xkcd_line([[-1, 9], [9, -1]], 0.01, 0.2, red):
display(
  x_axis, y_axis,
  seq( xkcd_line([[-2+0.3*r(), u+0.3*r()], [10+0.3*r(), u+0.3*r()]], 0.005, 0.5, gray), u in [seq(-1..9, 2)]),
  seq( xkcd_line([[u+0.3*r(), -2+0.3*r()], [u+0.3*r(), 10+0.3*r()]], 0.005, 0.5, gray), u in [seq(-1..9, 2)]),
  d1, d2,
  axes=none,
  scaling=constrained
)

 

# Axes and a couple of polygonal lines

d1 := xkcd_polyline([[0, 0], [1, 3], [3, 5], [7, 1], [9, 7]], 0.01, 1, red):
d2 := xkcd_polyline([[0, 9], [2, 8], [5, 2], [8, 3], [10, -1]], 0.01, 1, blue):

display(
  x_axis, y_axis,
  d1, d2,
  axes=none,
  scaling=constrained
)

 

# A few polygonal shapes

display(
  xkcd_polyline([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]], 0.01, 1, red),
  xkcd_polyline([[1/3, 1/3], [2/3, 1/3], [2/3, 4/3], [-1, 4/3], [1/3, 1/3]], 0.01, 1, blue),
  xkcd_polyline([[-1/3, -1/3], [4/3, 1/2], [1/2, 1/2], [1/2,-1], [-1/3, -1/3]], 0.01, 1, green),
  axes=none,
  scaling=constrained
)

 

# A few circles

cols  := [red, green, blue, gold, black]:                                # colors
cents := convert( Statistics:-Sample(Uniform(-1, 3), [5, 2]), listlist): # centers
radii := Statistics:-Sample(Uniform(1/2, 2), 5):                         # radii
lcs   := Statistics:-Sample(Uniform(0.2, 0.7), 5):                       # correlations lengths

display(
  seq(
    xkcd_circle(0.02, lcs[n], radii[n], cents[n], cols[n]),
    n=1..5
  ),
  axes=none,
  scaling=constrained
)

 

# A 3D drawing

x_axis := xkcd_line([[0, 0], [5, 0]], 0.01, 0.2, black):
y_axis := xkcd_line([[0, 0], [4, 2]], 0.01, 0.2, black):
z_axis := xkcd_line([[0, 0], [0, 5]], 0.01, 0.2, black):

f1 := 4*cos(x/6)-1:
F1 := xkcd_func(f1, [0.5, 5], 6, 0.001, 0.8, red):
F2 := xkcd_line([[0.5, eval(f1, x=0.5)], [3, 4]], 0.01, 0.2, red):
f3 := 4*cos((x-2)/6):
F3 := xkcd_func(f3, [3, 7], 6, 0.001, 0.8, red):
F4 := xkcd_line([[5, eval(f1, x=5)], [7, eval(f3, x=7)]], 0.01, 0.2, red):

dx := xkcd_line([[2, 1], [4, 1]], 0.01, 0.2, gray, lsty=3):
dy := xkcd_line([[2, 0], [4, 1]], 0.01, 0.2, gray, lsty=3):
dz := xkcd_line([[4, 1], [4, 3]], 0.01, 0.2, gray, lsty=3):

po := xkcd_circle(0.02, 0.3, 0.1, [4, 3], blue):

# Numerical value come from "probe info + copy/paste"

nvect   := xkcd_polyline([[4, 3], [4.57, 4.26], [4.35, 4.1], [4.57, 4.26], [4.58, 4.02]], 0.01, 1, blue):
tg1vect := xkcd_polyline([[4, 3], [4.78, 2.59], [4.49, 2.87], [4.78, 2.59], [4.46, 2.57]], 0.01, 1, blue):
tg2vect := xkcd_polyline([[4, 3], [4.79, 3.35], [4.70, 3.13], [4.79, 3.35], [4.46, 3.35]], 0.01, 1, blue):
rec1    := xkcd_polyline([[4.118, 3.286], [4.365, 3.396], [4.257, 3.108]], 0.01, 1, blue):
rec2    := xkcd_polyline([[4.257, 3.108], [4.476, 2.985], [4.259, 2.876]], 0.01, 1, blue):



display(
  x_axis, y_axis, z_axis,
  F1, F2, F3, F4,
  dx, dy, dz,
  po,
  nvect, tg1vect, tg2vect, rec1, rec2,
  axes=none,
  scaling=constrained
)

 

# Arrow

d1 := xkcd_polyline([[0, 0], [1, 0], [0.9, 0.05], [1, 0], [0.9, -0.05]], 0.01, 1, red):


T := (a, x0, y0, l) ->
             plottools:-transform(
               (x,y) -> [ x0 + l * (x*cos(a)-y*sin(a)), y0 + l * (x*sin(a)+y*cos(a)) ]
             ):


display(
  seq( T(2*Pi*n/10, 0.5, 0, 1/2)(
           display(
              xkcd_polyline(
                  [[0, 0], [1, 0], [0.9, 0.05], [1, 0], [0.9, -0.05]],
                  0.01,
                  1,
                  ColorTools:-Color([rand()/10^12, rand()/10^12, rand()/10^12])
               )
           )
        ),
       n=1..10
  ),
  axes=none,
  scaling=constrained
)

 

 


 

Download XKCD.mw

 

What is the best way to get some one on one training in maple , has anyone done this?

3 4 5 6 7 8 9 Last Page 5 of 1708