tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are answers submitted by tomleslie

  1. just because alternatives are good, and
  2. it is more directly related to your original problem

#
# Define test function and general Maclaurin
# series
#
  f:= x -> exp(x);
  mac:= (x,n) -> add(1/k!*D[1$k](f)(0)*x^k, k=0..n);
#
# Specify x-argument for test function and
# error criterion
#
  x_arg:=0.1:
  eps:=0.00001:
#
# Run a loop which 'breaks' when the desired error
# criterion is met
#
  for n from 0 do
      if   abs( f(x_arg)-mac(x_arg, n)) < eps
      then break
      fi:
  od;
#
# output desired index, and error
  n;
  abs( f(x_arg)-mac(x_arg, n));

proc (x) options operator, arrow; exp(x) end proc

 

proc (x, n) options operator, arrow; add((D[`$`(1, k)](f))(0)*x^k/factorial(k), k = 0 .. n) end proc

 

3

 

0.4251e-5

(1)

 

Download mac.mw

One of the variants in the following ought(?) to cover your requirement. NB plots render in a worksheet rather better than they do here (honest!)

  restart;
  with(LinearAlgebra):
  with(DynamicSystems):
#
# Geberate some more or less random data for illustrative
# purposes
#
  pts:=20:
  T:=Vector(pts, j->j):
  A:=RandomMatrix(pts, pts, generator=0.0..1.0):
#
# Produce a single 'stem' plot using the first row
# of the above matrix.
#
  p1:=DiscretePlot(T, A[1,..], style=stem, colour=red);
#
# Produce further plots, from successive rows, (offsetting
# these slightly in the x-direction, for the purposes
# of visibility
#
  p2:=DiscretePlot(T+~0.2, A[2,..], style=stem, color=blue):
  p3:=DiscretePlot(T+~0.4, A[3,..], style=stem, color=green):
  p4:=DiscretePlot(T+~0.6, A[4,..], style=stem, color=black):
  plots:-display([p1,p2,p3,p4]);
#
# Produce further plots, from successive rows, (offsetting
# these slightly in the y-direction, for the purposes
# of visibility
#
  p2:=DiscretePlot(T, A[2,..]+~1, style=stem, baseline=1, color=blue):
  p3:=DiscretePlot(T, A[3,..]+~2, style=stem, baseline=2, color=green):
  p4:=DiscretePlot(T, A[4,..]+~3, style=stem, baseline=3, color=black):
  plots:-display([p1,p2,p3,p4]);

 

 

 

 

Download stemPlot.mw

as in

restart;
A:= Array(  (1..3)$4,
                    (i, j, k, l) ->`if`
                                      ( `and`
                                         ( i=j, j=k, k=l ),
                                         1.,
                                         0.
                                      )
               ):
A[1,2,3,1];
A[2,2,2,2];

 

 

 

(for the determinant of a random matrix)

with(LinearAlgebra):
M:=RandomMatrix(4,4)/~100:
K:=evalf(Determinant(M)):
printf( "\n\n\n                The value of the determinant is %10.8f\n", K);




                The value of the determinant is 0.01677054

 

 

Download prPrint.mw

which produces 'stem' plots for both a time signal and  its discrete fourier transorm

  restart;
#
# Use somethng sensible as a 'signal'
#
  signal:= sin(t)*exp(-t^2);
#
# Generate a vector of time values
#
  T:=Vector( [seq( j, j=-10..10, 0.1)]):
#
# Sample the signal at the values given in
# time vector above, and store the results
# in a vector
#
  sampSignal:= Vector([seq( eval(signal, t=j), j in T)]):
#
# Produce a 'stem' plot of the time-domain signal
#
  DynamicSystems:-DiscretePlot(T, sampSignal, style=stem, size=[1200, 600]);
#
# Compute a DFT of the sample signal and produce
# a simple plot of its absolute value
#
  spec:= SignalProcessing:-DFT( sampSignal):
  plots:-listplot(abs~(spec), size=[1200, 600]);
#
# Or if you want the frequency domain plot of the
# absolute values as a 'stem' plot
#
  indf:=Vector([seq( j, j=1..op([2,2], spec))]):
  powf:=Vector([seq( abs(spec[j]),  j=1..op([2,2], spec))]):
  DynamicSystems:-DiscretePlot(indf, powf, style=stem, size=[1200, 600]);

sin(t)*exp(-t^2)

 

 

 

 

 

Download DFTstem.mw

the forst contains the term (1-t), where 't' is the integration variable. The second contains (1-alpha*T), where both 'alpha' an 'T' are constants. These are not equivalent, even if alpha=1

See the highlighted terms in the attached

``

n := 0; T := 2; a[0] := (int(0*exp(-I*(2*Pi*n*t/T)), t = -(1/2)*T .. 0)+int((1-t)*exp(-I*(2*Pi*n*t/T)), t = 0 .. (1/2)*T))/T

1/4

(1)

``

n := 0; alpha := 1; T := 2; a[0] := (int(0*exp(-I*(2*Pi*n*t/T)), t = -(1/2)*T .. 0)+int((-T*alpha+1)*exp(-I*(2*Pi*n*t/T)), t = 0 .. (1/2)*T))/T

-1/2

(2)

NULL

Download intProb.mw

to your problem, see the attached

  restart:
  with(LinearAlgebra):
#
# Define the 'size' of the problem and generate a
# couple of test msatrixes. OP seems to want this
# size to be 4, althugh no reason why we should be
# restricted to this single value. Just change the
# value of 'md' below to anything you want
#
  md:=8:
  A:=RandomMatrix(md,md);
  b:=RandomMatrix(md,md);
#
# Perform the calculation required by the OP
#
  for i from 1 to md do
      if   A[i,i]=0
      then break
      else for l from i to md do
               A[i,l]:=A[i,l]/A[i,i]:
               b[i,1]:=b[i,1]/A[i,i]:
           od:
           for j from i+1 to md do
               for k from i to md do
                   A[j,k]:=A[j,k]-A[j,i]*A[i,k]
               od:
               b[j,1]:=b[j,1]-A[j,i]*b[i,1]
           od:
      fi:
  od:
  A;

Matrix(8, 8, {(1, 1) = -62, (1, 2) = 99, (1, 3) = 24, (1, 4) = 31, (1, 5) = 50, (1, 6) = -38, (1, 7) = -93, (1, 8) = 8, (2, 1) = -33, (2, 2) = 60, (2, 3) = 65, (2, 4) = -50, (2, 5) = 10, (2, 6) = -18, (2, 7) = -76, (2, 8) = 69, (3, 1) = -68, (3, 2) = -95, (3, 3) = 86, (3, 4) = -80, (3, 5) = -16, (3, 6) = 87, (3, 7) = -72, (3, 8) = 99, (4, 1) = -67, (4, 2) = -20, (4, 3) = 20, (4, 4) = 43, (4, 5) = -9, (4, 6) = 33, (4, 7) = -2, (4, 8) = 29, (5, 1) = 22, (5, 2) = -25, (5, 3) = -61, (5, 4) = 25, (5, 5) = -50, (5, 6) = -98, (5, 7) = -32, (5, 8) = 44, (6, 1) = 14, (6, 2) = 51, (6, 3) = -48, (6, 4) = 94, (6, 5) = -22, (6, 6) = -77, (6, 7) = -74, (6, 8) = 92, (7, 1) = 16, (7, 2) = 76, (7, 3) = 77, (7, 4) = 12, (7, 5) = 45, (7, 6) = 57, (7, 7) = -4, (7, 8) = -31, (8, 1) = 9, (8, 2) = -44, (8, 3) = 9, (8, 4) = -2, (8, 5) = -81, (8, 6) = 27, (8, 7) = 27, (8, 8) = 67})

 

Matrix(8, 8, {(1, 1) = -36, (1, 2) = 10, (1, 3) = 95, (1, 4) = 5, (1, 5) = -23, (1, 6) = -14, (1, 7) = -82, (1, 8) = 52, (2, 1) = -69, (2, 2) = -44, (2, 3) = 63, (2, 4) = -91, (2, 5) = -63, (2, 6) = 60, (2, 7) = -70, (2, 8) = -13, (3, 1) = 69, (3, 2) = 26, (3, 3) = 10, (3, 4) = -44, (3, 5) = -26, (3, 6) = -35, (3, 7) = 41, (3, 8) = 82, (4, 1) = -15, (4, 2) = -3, (4, 3) = -61, (4, 4) = -38, (4, 5) = 30, (4, 6) = 21, (4, 7) = 91, (4, 8) = 72, (5, 1) = 2, (5, 2) = -62, (5, 3) = -26, (5, 4) = -38, (5, 5) = 10, (5, 6) = 90, (5, 7) = 29, (5, 8) = 42, (6, 1) = -88, (6, 2) = -83, (6, 3) = -20, (6, 4) = 91, (6, 5) = 22, (6, 6) = 80, (6, 7) = 70, (6, 8) = 18, (7, 1) = 99, (7, 2) = 9, (7, 3) = -78, (7, 4) = -1, (7, 5) = 12, (7, 6) = 19, (7, 7) = -32, (7, 8) = -59, (8, 1) = -59, (8, 2) = 88, (8, 3) = -4, (8, 4) = 63, (8, 5) = 45, (8, 6) = 88, (8, 7) = -1, (8, 8) = 12})

 

Matrix(%id = 18446744074329194494)

(1)

 

Download loopProb.mw

  1. Don't write code which can result in catastrophic errors. This is usually achieved by careful argument/parameter checking before executing any (possibly harmfull) statements. This is by far the best solution
  2. If the above (recommended) solution is too difficult for you, then you can attempt to enclose the (possibly) offending command within a try()..catch()..end, construct. For details see ?try

then you can get a response for any values of the (M, N, alpha) triple, as in

restart;
dosum:=(M, N, alpha) -> simplify(add(add(((-1)^i2*GAMMA(N-i2+alpha)*2^(N-2*i2)/(GAMMA(alpha)*factorial(i2)*factorial(N-2*i2)*(N-2*i2+1))*(GAMMA(k+1)*(k+alpha)*GAMMA(alpha)^2/(Pi*2^(1-2*alpha)*GAMMA(k+2*alpha))))*(add((1/2)*(-1)^i*GAMMA(k-i+alpha)*2^(k-2*i)*(1+(-1)^(N-2*i2+1+k-2*i))*GAMMA((1/2)*N-i2+1+(1/2)*k-i)*GAMMA(alpha+1/2)*L[k]/(GAMMA(alpha)*factorial(i)*factorial(k-2*i)*GAMMA(alpha+3/2+(1/2)*N-i2+(1/2)*k-i)), i = 0 .. floor((1/2)*k))), i2 = 0 .. floor((1/2)*N)), k = 0 .. M)):
dosum(4,2,1);
dosum(8,4,2);

-(1/6)*L[1]+(1/6)*L[3]

 

-(1/12)*L[3]+(1/12)*L[5]

(1)

 

Download dosum.mw

so returns nothing.

The next step is generally to use pdsolve(......, numeric), but if you try this for your system you will get the error message

Error, (in pdsolve/numeric) unable to handle elliptic PDEs.

If you (temporarily) discard the boundary conditions, then Maple will provide a general solution in termes of two arbitrary functions. Boundary conditions can then be applied in turn to generate relations between these arbitrary functions - and if you (or I) get lucky, one might be able to 'guess' some possibilities for these arbitrary functions. I failed at this point!

See the attached

restart;
pde := [ diff(u(x, y), x, x)+diff(u(x, y), y, y) = 2*Pi*(2*Pi*y^2-2*Pi*y-1)*exp(Pi*y*(1-y))*sin(Pi*x),
         u(0, y) = sin(Pi*y),
         u(1, y) = exp(Pi)*sin(Pi*y),
         u(x, 2) = exp(-2*Pi)*sin(Pi*x),
         u(x, 0) = u(x, 1)
       ];
 

[diff(diff(u(x, y), x), x)+diff(diff(u(x, y), y), y) = 2*Pi*(2*Pi*y^2-2*Pi*y-1)*exp(Pi*y*(1-y))*sin(Pi*x), u(0, y) = sin(Pi*y), u(1, y) = exp(Pi)*sin(Pi*y), u(x, 2) = exp(-2*Pi)*sin(Pi*x), u(x, 0) = u(x, 1)]

(1)

pdsolve(pde);

pdsolve(pde[1], pde[2..-1], numeric)

Error, (in pdsolve/numeric) unable to handle elliptic PDEs

 

sol:=pdsolve(pde[1], build);

u(x, y) = _F1(y-I*x)+_F2(y+I*x)+2*exp(-Pi*y*(-1+y))*tan((1/2)*Pi*x)/(1+tan((1/2)*Pi*x)^2)

(2)

#
# Apply boundary conditions in turn in the
# general solution to see if this gives any
# enlightenment about the nature of the
# functions _F1() and _F2()
#
  rhs(eval(sol, x=0))=sin(Pi*y);
  limit(rhs(sol), x=1)=exp(Pi)*sin(Pi*y);
  rhs(eval(sol, y=2))=exp(-2*Pi)*sin(Pi*x);
  rhs(eval(sol, y=0))-rhs(eval(sol, y=1))=0;

_F1(y)+_F2(y) = sin(Pi*y)

 

_F1(y-I)+_F2(y+I) = exp(Pi)*sin(Pi*y)

 

_F1(-I*x)+_F2(I*x)-_F1(1-I*x)-_F2(1+I*x) = 0

 

_F1(2-I*x)+_F2(2+I*x)+2*exp(-2*Pi)*tan((1/2)*Pi*x)/(1+tan((1/2)*Pi*x)^2) = exp(-2*Pi)*sin(Pi*x)

(3)

 

Download pdeProb.mw

 

  1. The fundamental problem seems to be that the 'label' and the 'equation number' are two completely different things, with a one-to-one correspondence between them
  2. What you see in the target worksheet (eg the file test.mw, uploaded by Marius Iwaniuk) are equation numbers, which run sequentially from (1)..(5)
  3. However to retrieve the associated expressions in a new worksheet, the "relevant labels" are L1, L10, L6, L7, L8 respectively
  4. Within the target worksheet I cannot find any way of discovering  the one-to-one correspondence between the 'equation numbers' and the 'labels'. I assume this is possible (somehow), but I can't figure it out
  5. The only method I have found to "retrieve" the relevant expressions in a new worksheet is to do this from the menus! Use Insert->Reference, navigate to the target file, (eg test.mw), select it, and click open. This produces a pop-up window, whose contents (for the file test.mw) are (1)..(5). Selecting one of these, the 'OK' will cause the complete DocumentTools:-Retrieve command to be generated within the new worksheet, together with required label - ie the appropriate entry from L1, L10, L6, L7, L8

See the attached: NB the path to the file test.mw will have to be changed for your installation. Note also I did not type the last five commands in this worksheet -they were generated automatically (see above)

restart; kernelopts(version)

`Maple 2018.0, X86 64 WINDOWS, Mar 9 2018, Build ID 1298750`

(1)

FileTools:-IsReadable("C:/Users/TomLeslie/Desktop/test.mw")

true

(2)

DocumentTools[Retrieve]("C:\\Users\\TomLeslie\\Desktop\\test.mw", "L1")

y(x) = _C1*exp(x)

(3)

DocumentTools[Retrieve]("C:\\Users\\TomLeslie\\Desktop\\test.mw", "L10")

3

(4)

DocumentTools[Retrieve]("C:\\Users\\TomLeslie\\Desktop\\test.mw", "L6")

y(x) = _C1*exp(x)+_C2*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+_C3*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)

(5)

DocumentTools[Retrieve]("C:\\Users\\TomLeslie\\Desktop\\test.mw", "L7")

y(x) = _C1*exp(-x)+_C2*exp(x)

(6)

DocumentTools[Retrieve]("C:\\Users\\TomLeslie\\Desktop\\test.mw", "L8")

Int(x, x)

(7)

 

Download getLabels.mw

 

to produce a plot of the vector field, valuse for F0 and rho0 have to be provided. You can either do this with the 'Explore' command as rlopez has suggested, or directly using the fieldplot3d() command as shown in the attached. In this worksheet, the 'eval command - ie eval(F1,[F0=2, rho__0=0.5]) - is used to enable evaluation of the field for specific values of the parameters F0 and rho__0

restart:
with(VectorCalculus):
with(plots):
SetCoordinates( 'cylindrical'[rho, phi, z]):
F1:=VectorField(<F0*rho^2/rho__0^2*exp(-(rho/rho__0)^2), F0*rho/rho__0*sin(phi)^2, F0>);
fieldplot3d(eval(F1,[F0=2, rho__0=0.5]), rho=0..1, phi=0..2*Pi, z=0..1);

Vector(3, {(1) = F0*rho^2*exp(-rho^2/`#msub(mi("&rho;",fontstyle = "normal"),mi("0"))`^2)/`#msub(mi("&rho;",fontstyle = "normal"),mi("0"))`^2, (2) = F0*rho*sin(phi)^2/`#msub(mi("&rho;",fontstyle = "normal"),mi("0"))`, (3) = F0})

 

 

 


 

Download FP.mw

 

I tried the example on the DocumentTools:-Retrieve help page, ie

restart;
kernelopts(version);
with(DocumentTools):
src := FileTools:-JoinPath(["example/BesselsEquation.mw"],base=datadir);
Retrieve( src, "L6");

`Maple 2018.0, X86 64 WINDOWS, Mar 9 2018, Build ID 1298750`

 

"C:\Program Files\Maple 2018\data\example/BesselsEquation.mw"

 

x^2*(diff(diff(y(x), x), x))+x*(diff(y(x), x))+(-nu^2+x^2)*y(x) = 0

(1)

 

Download retProb.mw

which works correctly on 64-bit win7

Upload code using the big green up-arrow in the Mapleprimes toolbar: no-one can do anything for sure with pictures.

Looking at the error message it is possible(?!) that you may have a problem with "implied multiplication" where you have typed

r(4*m+r)

rather than

r (4*m+r)    Note the space between 'r' and '('

when you mean r*(4*m+r).

This would be trivial for me to check if you had posted code. Pretty much impossible to check from pictures of code

I rewote your problem slightly

  1. Replaced all instances of sum() with add() - all sums are determined, with relatively few terms
  2. Rewrote the contents of your loop in two stages so that I could examine the expression being 'solved' This demonstrated that for K=0, 1, the first two expressions reduce to 0 and 0, hence U(2) and U(3) are arbitrary.
  3. For K=2, the expression contains U(2) and 'a', but no term in U(4), hence U(4) cannot be solved for (or is arbitrary, whichever you prefer). This continues for all subsequent values of 'K'

See the attached

solProb.mw

First 135 136 137 138 139 140 141 Last Page 137 of 207