tomleslie

13876 Reputation

20 Badges

15 years, 182 days

MaplePrimes Activity


These are replies submitted by tomleslie

are pretty easy: couldn't find any complex ones. Not saying the latter don't exist, just that I couldn't find them over the search areas I tried.

See the attached

restart; S3 := -(1/2*I)*(-(2*I)*exp(I*Pi*k*tau/T)*Pi*k-exp(I*Pi*k*tau/T)*T+I*exp(I*Pi*k*tau/T)*Pi*k*tau+(4*I)*Pi*k-(2*I)*exp(-I*Pi*k*tau/T)*Pi*k+exp(-I*Pi*k*tau/T)*T+I*exp(-I*Pi*k*tau/T)*Pi*k*tau)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

-((1/2)*I)*(-(2*I)*exp(I*Pi*k*tau/T)*Pi*k-exp(I*Pi*k*tau/T)*T+I*exp(I*Pi*k*tau/T)*Pi*k*tau+(4*I)*Pi*k-(2*I)*exp(-I*Pi*k*tau/T)*Pi*k+exp(-I*Pi*k*tau/T)*T+I*exp(-I*Pi*k*tau/T)*Pi*k*tau)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

(1)

"(->)"(-2*cos(Pi*k*tau/T)*Pi*k-sin(Pi*k*tau/T)*T+cos(Pi*k*tau/T)*Pi*k*tau+2*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

S3 = ((-I)*(1/2))*((I*Pi*k*tau-(2*I)*Pi*k)*(exp(I*Pi*k*tau/T)+exp(-I*Pi*k*tau/T))-T*(exp(I*Pi*k*tau/T)-exp(-I*Pi*k*tau/T))+(4*I)*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

-((1/2)*I)*(-(2*I)*exp(I*Pi*k*tau/T)*Pi*k-exp(I*Pi*k*tau/T)*T+I*exp(I*Pi*k*tau/T)*Pi*k*tau+(4*I)*Pi*k-(2*I)*exp(-I*Pi*k*tau/T)*Pi*k+exp(-I*Pi*k*tau/T)*T+I*exp(-I*Pi*k*tau/T)*Pi*k*tau)*sin(2*Pi*k*x/T)/(Pi^2*k^2) = -((1/2)*I)*((I*Pi*k*tau-(2*I)*Pi*k)*(exp(I*Pi*k*tau/T)+exp(-I*Pi*k*tau/T))-T*(exp(I*Pi*k*tau/T)-exp(-I*Pi*k*tau/T))+(4*I)*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

(2)

"(->)"true"(->)"true

convert(S3, trig) = (-2*cos(Pi*k*tau/T)*Pi*k-sin(Pi*k*tau/T)*T+cos(Pi*k*tau/T)*Pi*k*tau+2*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

-((1/2)*I)*(-(2*I)*(cos(Pi*k*tau/T)+I*sin(Pi*k*tau/T))*Pi*k-(cos(Pi*k*tau/T)+I*sin(Pi*k*tau/T))*T+I*(cos(Pi*k*tau/T)+I*sin(Pi*k*tau/T))*Pi*k*tau+(4*I)*Pi*k-(2*I)*(cos(Pi*k*tau/T)-I*sin(Pi*k*tau/T))*Pi*k+(cos(Pi*k*tau/T)-I*sin(Pi*k*tau/T))*T+I*(cos(Pi*k*tau/T)-I*sin(Pi*k*tau/T))*Pi*k*tau)*sin(2*Pi*k*x/T)/(Pi^2*k^2) = (-2*cos(Pi*k*tau/T)*Pi*k-sin(Pi*k*tau/T)*T+cos(Pi*k*tau/T)*Pi*k*tau+2*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

(3)

"(->)"true"(->)"trueNULL

 

Set the following for the Fourier coeffs:NULL

Ck := simplify(convert(S3, trig)/sin(2*Pi*k*x/T), size)

(Pi*k*(tau-2)*cos(Pi*k*tau/T)-sin(Pi*k*tau/T)*T+2*Pi*k)/(Pi^2*k^2)

(4)

 

``

T := N*tau; m := 10; a[0] := 0; N := 2; tau := 2; T; Ck

(-4*sin((1/2)*Pi*k)+2*Pi*k)/(Pi^2*k^2)

(5)

Plot the results:NULLNULL

plots[display](plot(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 5), x = -2 .. 2, numpoints = 400, axis[1] = [mode = linear], axis[2] = [mode = linear]), plot(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 10), x = -2 .. 2, color = "LimeGreen"), plot(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 20), x = -2 .. 2, color = "Blue"), plot(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 50), x = -2 .. 2, color = "Orange"))

 

 

plots[display](plot(diff(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 5), x), x = -1 .. 1, numpoints = 400, axis[1] = [mode = linear], axis[2] = [mode = linear]), plot(diff(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 10), x), x = -1 .. 1, color = "LimeGreen"), plot(diff(a[0]+sum(Ck*sin(2*Pi*k*x/T), k = 1 .. 20), x), x = -1 .. 1, color = "Blue"))

 

 

NULL

NULL

#
# Set number of terms to be used in the summation
# and the number of roots to be determined (in the
# case of real roots. I tested this up to 100000
# terms in the sum and 100 roots (for the case of
# real roots): this took about 120secs on my machine,
# with a memory usage of 2MiB. With the supplied values
# below, calculation took about 13secs on my machine
# and still used only 2MiB
#
# Write the sequentisl root-finding process as a
# procedure just to facilitate resource reporting
#
  nTerms:=10000:
  nRoots:=100:
  getRoots:= proc( sumTerms, numRoots)
                   uses RootFinding:
                   local i,
                         rts:= Array(0..numRoots),
                         f:= unapply
                             ( diff( a[0]
                                     +
                                     Sum
                                     ( Ck*sin(2*Pi*k*x/T),
                                       k = 1 .. sumTerms
                                     ),
                                     x
                                   ),
                               x
                             );
                   for i from 1 to numRoots do
                       rts[i]:= NextZero(f, rts[i-1]);
                   od:
                   return rts[1..numRoots]:
             end proc:
  rts:=CodeTools:-Usage(getRoots(nTerms, nRoots));
  rts[1..floor(sqrt(nRoots))];

memory used=2.34MiB, alloc change=0 bytes, cpu time=13.37s, real time=13.37s, gc time=0ns

 

rts := Array(1..100, {(1) = 0.1999700038e-3, (2) = 0.4000199997e-3, (3) = 0.5999100115e-3, (4) = 0.8000399994e-3, (5) = 0.9998500192e-3, (6) = 0.1200059999e-2, (7) = 0.1399790026e-2, (8) = 0.1600079999e-2, (9) = 0.1799730034e-2, (10) = 0.2000099998e-2, (11) = 0.2199670042e-2, (12) = 0.2400119998e-2, (13) = 0.2599610049e-2, (14) = 0.2800139998e-2, (15) = 0.2999550057e-2, (16) = 0.3200159998e-2, (17) = 0.3399490064e-2, (18) = 0.3600179998e-2, (19) = 0.3799430071e-2, (20) = 0.4000199999e-2, (21) = 0.4199370078e-2, (22) = 0.4400219999e-2, (23) = 0.4599310085e-2, (24) = 0.4800240000e-2, (25) = 0.4999250092e-2, (26) = 0.5200260000e-2, (27) = 0.5399190099e-2, (28) = 0.5600280001e-2, (29) = 0.5799130106e-2, (30) = 0.6000300002e-2, (31) = 0.6199070112e-2, (32) = 0.6400320003e-2, (33) = 0.6599010118e-2, (34) = 0.6800340005e-2, (35) = 0.6998950124e-2, (36) = 0.7200360006e-2, (37) = 0.7398890130e-2, (38) = 0.7600380008e-2, (39) = 0.7798830136e-2, (40) = 0.8000400010e-2, (41) = 0.8198770141e-2, (42) = 0.8400420012e-2, (43) = 0.8598710146e-2, (44) = 0.8800440015e-2, (45) = 0.8998650151e-2, (46) = 0.9200460017e-2, (47) = 0.9398590155e-2, (48) = 0.9600480020e-2, (49) = 0.9798530160e-2, (50) = 0.1000050002e-1, (51) = 0.1019847016e-1, (52) = 0.1040052002e-1, (53) = 0.1059841016e-1, (54) = 0.1080054003e-1, (55) = 0.1099835017e-1, (56) = 0.1120056003e-1, (57) = 0.1139829017e-1, (58) = 0.1160058004e-1, (59) = 0.1179823017e-1, (60) = 0.1200060004e-1, (61) = 0.1219817017e-1, (62) = 0.1240062005e-1, (63) = 0.1259811018e-1, (64) = 0.1280064005e-1, (65) = 0.1299805018e-1, (66) = 0.1320066006e-1, (67) = 0.1339799018e-1, (68) = 0.1360068006e-1, (69) = 0.1379793018e-1, (70) = 0.1400070007e-1, (71) = 0.1419787018e-1, (72) = 0.1440072008e-1, (73) = 0.1459781018e-1, (74) = 0.1480074008e-1, (75) = 0.1499775018e-1, (76) = 0.1520076009e-1, (77) = 0.1539769018e-1, (78) = 0.1560078010e-1, (79) = 0.1579763018e-1, (80) = 0.1600080011e-1, (81) = 0.1619757018e-1, (82) = 0.1640082012e-1, (83) = 0.1659751017e-1, (84) = 0.1680084013e-1, (85) = 0.1699745017e-1, (86) = 0.1720086014e-1, (87) = 0.1739739017e-1, (88) = 0.1760088015e-1, (89) = 0.1779733016e-1, (90) = 0.1800090016e-1, (91) = 0.1819727016e-1, (92) = 0.1840092017e-1, (93) = 0.1859721016e-1, (94) = 0.1880094019e-1, (95) = 0.1899715015e-1, (96) = 0.1920096020e-1, (97) = 0.1939709014e-1, (98) = 0.1960098021e-1, (99) = 0.1979703014e-1, (100) = 0.2000100023e-1})

 

Array(%id = 18446744074370566854)

(6)

#
# Now let's go for complex roots - just because the OP
# wants to! Since one is now searching over a rectangular
# area rather than a line, restrict the linear dimensions
# of the search rectangle, so that one only gets sqrt(nRoots)
# along the real line. For no particular reason, restrict
# the imaginary range to +/- the value of the real range.
#
# This ought (at least) to produce the same sqrt(nRoots)
# along the real line as given by directly by the "real"
# rootfinding process above - and hopefully(?) some other
# complex values
#
# Also need to 'sort' the roots by the value of the real
# part to facilitate comparison with the output of the
# previous command
#
# With the above test values, ie 10000 terms in the sum,
# and number of roots =100, where we are making the guess
# that there will be 10 along the real axis, and the same
# root 'density' in the imaginary direction, this might
# or might not produce 100 complex roots
#
# Resource usage on my machine: takes about 2minutes and
# memory~14GiB (!)
#
# And it only found the 10 real roots, which were 'known'
# to lie in this range: ie no 'complex' roots at all!
#
  f:= unapply
      ( diff
        ( a[0] + Sum
                 ( Ck*sin(2*Pi*k*x/T),
                   k = 1 .. nTerms
                 ),
          x
        ),
        x
      ):
  cRoots:= CodeTools:-Usage
                      ( sort
                        ( [ RootFinding:-Analytic
                            ( evalf(f(x)),
                              x,
                              re=0..rts[floor(sqrt(nRoots))],
                              im=-rts[floor(sqrt(nRoots))]..rts[floor(sqrt(nRoots))]
                            )
                          ],
                          (a,b)->Re(a)<Re(b)
                        )
                      );

memory used=12.79GiB, alloc change=345.49MiB, cpu time=2.13m, real time=116.29s, gc time=22.89s

 

[0.199970003862748e-3, 0.400019999728541e-3, 0.599910011582420e-3, 0.800039999469425e-3, 0.999850019283625e-3, 0.120005999923329e-2, 0.139979002695384e-2, 0.160007999903220e-2, 0.179973003458249e-2]

(7)

 

NULL

Download getRoots.mw

Plot is the "wrong way round" - surely more common to have the y-axis be the dependent variable, so a minor revision of the above

 

restart;
Sol:=proc(omega,alpha,M,B,L,C)
local A, BCs, Eq;
A := -(alpha*exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))*omega+alpha*exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))+exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))*omega-alpha*omega+exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))-alpha-omega-1)/sqrt((omega+1)*omega*(M^2+alpha+1));
#printf( "%a\n", A);
Eq:=(1+B)*(diff(theta(eta), eta, eta))+C*A*(diff(theta(eta), eta))= 0;
BCs := (D(theta))(0) = -1,  theta(L)=0;
dsolve({Eq, BCs}, numeric);
end proc:
sol:=Sol(1,2,3,4,5,1);
plots:-odeplot(sol, [eta, theta(eta)], eta=0..5, scaling=constrained);

proc (x_bvp) local res, data, solnproc, _ndsol, outpoint, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then outpoint := evalf[_EnvDSNumericSaveDigits](x_bvp) else outpoint := evalf(x_bvp) end if; data := Array(1..4, {(1) = proc (outpoint) local X, Y, YP, yout, errproc, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; X := Vector(13, {(1) = .0, (2) = .39056008851417295, (3) = .7835200271664639, (4) = 1.1812508384208718, (5) = 1.5852822953081507, (6) = 1.996705130252933, (7) = 2.41590427557818, (8) = 2.842462040845942, (9) = 3.2757864464034157, (10) = 3.71502175407545, (11) = 4.158850493667046, (12) = 4.595834037341028, (13) = 5.0}, datatype = float[8], order = C_order); Y := Matrix(13, 2, {(1, 1) = 3.146149009375716, (1, 2) = -1.0, (2, 1) = 2.760306444647921, (2, 2) = -.9664901603376084, (3, 1) = 2.3932683197513396, (3, 2) = -.8988901295928134, (4, 1) = 2.050829920746934, (4, 2) = -.8229296527090515, (5, 1) = 1.7336315846176944, (5, 2) = -.7479853726464958, (6, 1) = 1.4406719688501886, (6, 2) = -.6771636595131107, (7, 1) = 1.1708183768475031, (7, 2) = -.6113764650671343, (8, 1) = .9231678743133844, (8, 2) = -.5508169241895727, (9, 1) = .6967079812387826, (9, 2) = -.4953784613766708, (10, 1) = .49041411447789257, (10, 2) = -.4448572231998396, (11, 1) = .3033267164490136, (11, 2) = -.39903350739483706, (12, 1) = .1379633810484315, (12, 2) = -.3585288731423135, (13, 1) = .0, (13, 2) = -.3247351636506393}, datatype = float[8], order = C_order); YP := Matrix(13, 2, {(1, 1) = -1.0, (1, 2) = -.0, (2, 1) = -.9664901603376084, (2, 2) = .1457923264937273, (3, 1) = -.8988901295928134, (3, 2) = .18787691906618312, (4, 1) = -.8229296527090515, (4, 2) = .1904116712460686, (5, 1) = -.7479853726464958, (5, 2) = .17944647620274307, (6, 1) = -.6771636595131107, (6, 2) = .1646240945880877, (7, 1) = -.6113764650671343, (7, 2) = .149353000321228, (8, 1) = -.5508169241895727, (8, 2) = .13479431670848935, (9, 1) = -.4953784613766708, (9, 2) = .12130270565908197, (10, 1) = -.4448572231998396, (10, 2) = .10895515147577188, (11, 1) = -.39903350739483706, (11, 2) = 0.9773916789398031e-1, (12, 1) = -.3585288731423135, (12, 2) = 0.8782014588459972e-1, (13, 1) = -.3247351636506393, (13, 2) = 0.7954316365080058e-1}, datatype = float[8], order = C_order); errproc := proc (x_bvp) local outpoint, X, Y, yout, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; Digits := 15; outpoint := evalf(x_bvp); X := Vector(13, {(1) = .0, (2) = .39056008851417295, (3) = .7835200271664639, (4) = 1.1812508384208718, (5) = 1.5852822953081507, (6) = 1.996705130252933, (7) = 2.41590427557818, (8) = 2.842462040845942, (9) = 3.2757864464034157, (10) = 3.71502175407545, (11) = 4.158850493667046, (12) = 4.595834037341028, (13) = 5.0}, datatype = float[8], order = C_order); Y := Matrix(13, 2, {(1, 1) = -0.20633824422377228e-6, (1, 2) = .0, (2, 1) = -0.1587811854221768e-6, (2, 2) = 0.23334482232583618e-7, (3, 1) = -0.11479624963627439e-6, (3, 2) = 0.3113865720806113e-7, (4, 1) = -0.8845600477776927e-7, (4, 2) = 0.31261170860229515e-7, (5, 1) = -0.7096022759558231e-7, (5, 2) = 0.29388005570051327e-7, (6, 1) = -0.5758289476284335e-7, (6, 2) = 0.2702860204898444e-7, (7, 1) = -0.4633929459140565e-7, (7, 2) = 0.2462338847040824e-7, (8, 1) = -0.3642117881932779e-7, (8, 2) = 0.22323175666749462e-7, (9, 1) = -0.2748535836331128e-7, (9, 2) = 0.20180710433089313e-7, (10, 1) = -0.19377738759605875e-7, (10, 2) = 0.18210805478623323e-7, (11, 1) = -0.12020211225446677e-7, (11, 2) = 0.16413921647044877e-7, (12, 1) = -0.5491667517463665e-8, (12, 2) = 0.14816198008765129e-7, (13, 1) = .0, (13, 2) = 0.13471258438678123e-7}, datatype = float[8], order = C_order); if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "right" then return X[13] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(2.0633824422377228e-7) elif outpoint = "errorproc" then error "this is already the error procedure" elif outpoint = "rawdata" then return [2, 13, [theta(eta), diff(theta(eta), eta)], X, Y] else return ('procname')(x_bvp) end if end if; if outpoint < X[1] or X[13] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[13] end if; V := array([1 = 4, 2 = 0]); if Digits <= trunc(evalhf(Digits)) then L := Vector(4, 'datatype' = 'float'[8]); yout := Vector(2, 'datatype' = 'float'[8]); evalhf(`dsolve/numeric/lagrange`(13, 2, X, Y, outpoint, var(yout), var(L), var(V))) else L := Vector(4, 'datatype' = 'sfloat'); yout := Vector(2, 'datatype' = 'sfloat'); `dsolve/numeric/lagrange`(13, 2, X, Y, outpoint, yout, L, V) end if; [eta = outpoint, seq('[theta(eta), diff(theta(eta), eta)]'[i] = yout[i], i = 1 .. 2)] end proc; if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "method" then return "bvp" elif outpoint = "right" then return X[13] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(2.0633824422377228e-7) elif outpoint = "errorproc" then return eval(errproc) elif outpoint = "rawdata" then return [2, 13, "depnames", X, Y, YP] else error "non-numeric value" end if end if; if outpoint < X[1] or X[13] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[13] end if; if Digits <= trunc(evalhf(Digits)) and (_EnvInFsolve <> true or _EnvDSNumericSaveDigits <= trunc(evalhf(Digits))) then V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (false), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = .0, (2, 2) = .0, (3, 1) = .0, (3, 2) = .0, (4, 1) = .0, (4, 2) = .0, (5, 1) = .0, (5, 2) = .0, (6, 1) = .0, (6, 2) = .0, (7, 1) = .0, (7, 2) = .0}, datatype = float[8], order = C_order); yout := Vector(2, {(1) = .0, (2) = .0}, datatype = float[8]); evalhf(`dsolve/numeric/hermite`(13, 2, X, Y, YP, outpoint, var(yout), var(L), var(V))) else if _EnvInFsolve = true then Digits := _EnvDSNumericSaveDigits end if; V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (false), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = 0., (1, 2) = 0., (2, 1) = 0., (2, 2) = 0., (3, 1) = 0., (3, 2) = 0., (4, 1) = 0., (4, 2) = 0., (5, 1) = 0., (5, 2) = 0., (6, 1) = 0., (6, 2) = 0., (7, 1) = 0., (7, 2) = 0.}, order = C_order); yout := Vector(2, {(1) = 0., (2) = 0.}); `dsolve/numeric/hermite`(13, 2, X, Y, YP, outpoint, yout, L, V) end if; [outpoint, seq(yout[i], i = 1 .. 2)] end proc, (2) = Array(0..0, {}), (3) = [eta, theta(eta), diff(theta(eta), eta)], (4) = 0}); solnproc := data[1]; if not type(outpoint, 'numeric') then if outpoint = "solnprocedure" then return eval(solnproc) elif member(outpoint, ["start", "left", "right", "errorproc", "rawdata", "order", "error"]) then return solnproc(x_bvp) elif outpoint = "sysvars" then return data[3] elif procname <> unknown then return ('procname')(x_bvp) else _ndsol := pointto(data[2][0]); return ('_ndsol')(x_bvp) end if end if; try res := solnproc(outpoint); [eta = res[1], seq('[theta(eta), diff(theta(eta), eta)]'[i] = res[i+1], i = 1 .. 2)] catch: error  end try end proc

 

 

 

Download odeProb2.mw

 

@Kitonum 

The reason you have supplied an "extra" boundary condition is because you have not defined a value for the quantity 'C', Surely it would be better to assign 'C' a value, and only use the boundary conditions which the OP supplied, as in the attached


 

 

restart;
Sol:=proc(omega,alpha,M,B,L,C)
local A, BCs, Eq;
A := -(alpha*exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))*omega+alpha*exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))+exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))*omega-alpha*omega+exp(-sqrt((omega+1)*omega*(M^2+alpha+1))*eta/(omega+1))-alpha-omega-1)/sqrt((omega+1)*omega*(M^2+alpha+1));
#printf( "%a\n", A);
Eq:=(1+B)*(diff(theta(eta), eta, eta))+C*A*(diff(theta(eta), eta))= 0;
BCs := (D(theta))(0) = -1,  theta(L)=0;
dsolve({Eq, BCs}, numeric);
end proc:
sol:=Sol(1,2,3,4,5,1);
plots:-odeplot(sol, [theta(eta), eta], eta=0..5, scaling=constrained);

proc (x_bvp) local res, data, solnproc, _ndsol, outpoint, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then outpoint := evalf[_EnvDSNumericSaveDigits](x_bvp) else outpoint := evalf(x_bvp) end if; data := Array(1..4, {(1) = proc (outpoint) local X, Y, YP, yout, errproc, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; X := Vector(13, {(1) = .0, (2) = .39056008851417295, (3) = .7835200271664639, (4) = 1.1812508384208718, (5) = 1.5852822953081507, (6) = 1.996705130252933, (7) = 2.41590427557818, (8) = 2.842462040845942, (9) = 3.2757864464034157, (10) = 3.71502175407545, (11) = 4.158850493667046, (12) = 4.595834037341028, (13) = 5.0}, datatype = float[8], order = C_order); Y := Matrix(13, 2, {(1, 1) = 3.146149009375716, (1, 2) = -1.0, (2, 1) = 2.760306444647921, (2, 2) = -.9664901603376084, (3, 1) = 2.3932683197513396, (3, 2) = -.8988901295928134, (4, 1) = 2.050829920746934, (4, 2) = -.8229296527090515, (5, 1) = 1.7336315846176944, (5, 2) = -.7479853726464958, (6, 1) = 1.4406719688501886, (6, 2) = -.6771636595131107, (7, 1) = 1.1708183768475031, (7, 2) = -.6113764650671343, (8, 1) = .9231678743133844, (8, 2) = -.5508169241895727, (9, 1) = .6967079812387826, (9, 2) = -.4953784613766708, (10, 1) = .49041411447789257, (10, 2) = -.4448572231998396, (11, 1) = .3033267164490136, (11, 2) = -.39903350739483706, (12, 1) = .1379633810484315, (12, 2) = -.3585288731423135, (13, 1) = .0, (13, 2) = -.3247351636506393}, datatype = float[8], order = C_order); YP := Matrix(13, 2, {(1, 1) = -1.0, (1, 2) = -.0, (2, 1) = -.9664901603376084, (2, 2) = .1457923264937273, (3, 1) = -.8988901295928134, (3, 2) = .18787691906618312, (4, 1) = -.8229296527090515, (4, 2) = .1904116712460686, (5, 1) = -.7479853726464958, (5, 2) = .17944647620274307, (6, 1) = -.6771636595131107, (6, 2) = .1646240945880877, (7, 1) = -.6113764650671343, (7, 2) = .149353000321228, (8, 1) = -.5508169241895727, (8, 2) = .13479431670848935, (9, 1) = -.4953784613766708, (9, 2) = .12130270565908197, (10, 1) = -.4448572231998396, (10, 2) = .10895515147577188, (11, 1) = -.39903350739483706, (11, 2) = 0.9773916789398031e-1, (12, 1) = -.3585288731423135, (12, 2) = 0.8782014588459972e-1, (13, 1) = -.3247351636506393, (13, 2) = 0.7954316365080058e-1}, datatype = float[8], order = C_order); errproc := proc (x_bvp) local outpoint, X, Y, yout, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; Digits := 15; outpoint := evalf(x_bvp); X := Vector(13, {(1) = .0, (2) = .39056008851417295, (3) = .7835200271664639, (4) = 1.1812508384208718, (5) = 1.5852822953081507, (6) = 1.996705130252933, (7) = 2.41590427557818, (8) = 2.842462040845942, (9) = 3.2757864464034157, (10) = 3.71502175407545, (11) = 4.158850493667046, (12) = 4.595834037341028, (13) = 5.0}, datatype = float[8], order = C_order); Y := Matrix(13, 2, {(1, 1) = -0.20633824422377228e-6, (1, 2) = .0, (2, 1) = -0.1587811854221768e-6, (2, 2) = 0.23334482232583618e-7, (3, 1) = -0.11479624963627439e-6, (3, 2) = 0.3113865720806113e-7, (4, 1) = -0.8845600477776927e-7, (4, 2) = 0.31261170860229515e-7, (5, 1) = -0.7096022759558231e-7, (5, 2) = 0.29388005570051327e-7, (6, 1) = -0.5758289476284335e-7, (6, 2) = 0.2702860204898444e-7, (7, 1) = -0.4633929459140565e-7, (7, 2) = 0.2462338847040824e-7, (8, 1) = -0.3642117881932779e-7, (8, 2) = 0.22323175666749462e-7, (9, 1) = -0.2748535836331128e-7, (9, 2) = 0.20180710433089313e-7, (10, 1) = -0.19377738759605875e-7, (10, 2) = 0.18210805478623323e-7, (11, 1) = -0.12020211225446677e-7, (11, 2) = 0.16413921647044877e-7, (12, 1) = -0.5491667517463665e-8, (12, 2) = 0.14816198008765129e-7, (13, 1) = .0, (13, 2) = 0.13471258438678123e-7}, datatype = float[8], order = C_order); if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "right" then return X[13] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(2.0633824422377228e-7) elif outpoint = "errorproc" then error "this is already the error procedure" elif outpoint = "rawdata" then return [2, 13, [theta(eta), diff(theta(eta), eta)], X, Y] else return ('procname')(x_bvp) end if end if; if outpoint < X[1] or X[13] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[13] end if; V := array([1 = 4, 2 = 0]); if Digits <= trunc(evalhf(Digits)) then L := Vector(4, 'datatype' = 'float'[8]); yout := Vector(2, 'datatype' = 'float'[8]); evalhf(`dsolve/numeric/lagrange`(13, 2, X, Y, outpoint, var(yout), var(L), var(V))) else L := Vector(4, 'datatype' = 'sfloat'); yout := Vector(2, 'datatype' = 'sfloat'); `dsolve/numeric/lagrange`(13, 2, X, Y, outpoint, yout, L, V) end if; [eta = outpoint, seq('[theta(eta), diff(theta(eta), eta)]'[i] = yout[i], i = 1 .. 2)] end proc; if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "method" then return "bvp" elif outpoint = "right" then return X[13] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(2.0633824422377228e-7) elif outpoint = "errorproc" then return eval(errproc) elif outpoint = "rawdata" then return [2, 13, "depnames", X, Y, YP] else error "non-numeric value" end if end if; if outpoint < X[1] or X[13] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[13] end if; if Digits <= trunc(evalhf(Digits)) and (_EnvInFsolve <> true or _EnvDSNumericSaveDigits <= trunc(evalhf(Digits))) then V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (false), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = .0, (2, 2) = .0, (3, 1) = .0, (3, 2) = .0, (4, 1) = .0, (4, 2) = .0, (5, 1) = .0, (5, 2) = .0, (6, 1) = .0, (6, 2) = .0, (7, 1) = .0, (7, 2) = .0}, datatype = float[8], order = C_order); yout := Vector(2, {(1) = .0, (2) = .0}, datatype = float[8]); evalhf(`dsolve/numeric/hermite`(13, 2, X, Y, YP, outpoint, var(yout), var(L), var(V))) else if _EnvInFsolve = true then Digits := _EnvDSNumericSaveDigits end if; V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (false), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = 0., (1, 2) = 0., (2, 1) = 0., (2, 2) = 0., (3, 1) = 0., (3, 2) = 0., (4, 1) = 0., (4, 2) = 0., (5, 1) = 0., (5, 2) = 0., (6, 1) = 0., (6, 2) = 0., (7, 1) = 0., (7, 2) = 0.}, order = C_order); yout := Vector(2, {(1) = 0., (2) = 0.}); `dsolve/numeric/hermite`(13, 2, X, Y, YP, outpoint, yout, L, V) end if; [outpoint, seq(yout[i], i = 1 .. 2)] end proc, (2) = Array(0..0, {}), (3) = [eta, theta(eta), diff(theta(eta), eta)], (4) = 0}); solnproc := data[1]; if not type(outpoint, 'numeric') then if outpoint = "solnprocedure" then return eval(solnproc) elif member(outpoint, ["start", "left", "right", "errorproc", "rawdata", "order", "error"]) then return solnproc(x_bvp) elif outpoint = "sysvars" then return data[3] elif procname <> unknown then return ('procname')(x_bvp) else _ndsol := pointto(data[2][0]); return ('_ndsol')(x_bvp) end if end if; try res := solnproc(outpoint); [eta = res[1], seq('[theta(eta), diff(theta(eta), eta)]'[i] = res[i+1], i = 1 .. 2)] catch: error  end try end proc

 

 

 

Download odeProb.mw

in the toolbar to post you worksheet here

@das1404 

As a general rule, one does not want to print the result of any calculation which happens in a procedure. One is only interested in the data which is returned, when the procedure is called.

Realistically, the 'printlevel' command is a kind of "poor person's debugger" - it will enable the printing of output which would normally be suppressed. It should not be used to produce "desired output" from a procedure. - that's what a 'return' statement is for.

Even fixing the above, I still think that your algorithm is unnecessarily complicated for what you are trying to achieve. However I have cleaned it up as much as I can.

The makeY() procedure now calculates a single 'frame' of the desired animation. I have also used the left/right symmetry on the upper 'arms' of the calculation - you don't have to calculate bot arms explicitly.

These 'frames' are called/displayed in a separate display() command to produce the desired animation. See the attached

A caveat - this was produced in current Maple - it *might* not work in Maple 7. I have no realsitic way to check this

  restart:
  makeY:= proc( x0, y0, h, base, w, alfa, tt, nf)
              #
              # Produces a single frame of the desired
              # animation
              #
                uses plots, plottools:
                local depth, lY, uY, opts, Up_leg,
                      x1, x2, x3, x4, x5, x6,
                      y1, y2, y3, y4, y5, y6,
                      P1_x, P2_x, P3_x, P1_y, P2_y, P3_y, P4_y,
                      xM_L, yM_L, xM_R, yM_R,
                      poly_YL_Up, poly_YL_Lo, poly_YR_Up, poly_YR_Lo:
                opts:= scaling=constrained,
                       style=patchnogrid,
                       axes=normal,
                       color=grey:
                lY:= w/sin(alfa):
                depth:= (base/2-lY)*abs(tan(alfa));
                uY:= h-(base-w)/2*abs(tan(alfa)):
                x1:= x0-w/2:
                y1:= y0+uY:
                x2:= x0-base/2:
                y2:= y0+h:
                x3:= x0+lY-base/2:
                y3:= y0+h:
                x4:= x0:
                y4:= y0+h-depth:
                xM_L:= (x1+x2)/2:
                yM_L:= (y1+y2)/2:
                xM_R:= (x3+x4)/2:
                yM_R:= (y3+y4)/2:
                x5:= x0-base/2:
                y5:= y0+uY:
                x6:= x0-base/2+w:
                y6:= y0+uY+w:
                P1_x:= xM_L+(x5-xM_L)*tt/nf:
                P1_y:= yM_L+(y5-yM_L)*tt/nf:
                P2_x:= xM_R+(x6-xM_R)*tt/nf:
                P2_y:= yM_R+(y6-yM_R)*tt/nf:
                P3_x:= x3+(x2+w-x3)*tt/nf:
                P3_y:= y2:
                P4_y:= y0+h-depth-(h-depth-uY-w)*tt/nf:
                poly_YL_Up:= polygon( [ [P1_x, P1_y],
                                        [x2,   y2],
                                        [P3_x, P3_y],
                                        [P2_x, P2_y]
                                      ]
                                ):
                poly_YL_Lo:= polygon( [ [x1,   y1],
                                        [P1_x, P1_y],
                                        [P2_x, P2_y],
                                        [x4,   P4_y]
                                      ]
                                    ):
                Up_leg:= rectangle( [ x0-w/2, y0+h-depth-(h-depth-uY-w)*tt/nf ],
                                    [ x0+w/2, y0]
                                  ):
                return display( poly_YL_Up,
                                poly_YL_Lo,
                                Up_leg,
                                reflect( poly_YL_Up, [ [0,0], [0, 1] ]),
                                reflect( poly_YL_Lo, [ [0,0], [0, 1] ]),
                                opts
                              );
      end proc:
#
# Call frames as necessary, and display animation
#
  nframes:=40:
  plots:-display( seq
                  ( makeY(0, 0, 12, 7.8, 1.5, 1.12, t, nframes),
                    t=0..nframes
                  ),
                  insequence=true,
                  axes=none
                );

 

 

 

Download doY.mws

@Carl Love 

OP has the first couple of statements in the 'for' loop defined as

for i from n-1 do
     k0=f(x, u[i])

Leaving aside (for the moment), that 'f' is undefined: since n is defined as 20 - where is u[19] defined??.

Now if the 'for' loop were

for i from 0 to n-1 do
     k0=f(x, u[i])

everything would be hunky-dory - assuming a defintion of f() is forthcoming

Try this simple extension od Acer's code

restart;
v := 1: L := 12:
PDE := (D[2, 2](u))(x, t) = v^2*(D[1, 1](u))(x, t):
BC := u(0, t) = 0,
           u(L, t) = 0:
IC := u(x, 0) = 3*exp(-(x-6)^2)-3*exp(-36),
         (D[2](u))(x, 0) = sin(x):
sol := pdsolve( PDE, {BC, IC},
                          numeric,
                          spacestep = 1/200,
                           timestep = 1/100
                       ):
sol:-plot(u(x,t), t=10, x=0..10);
#sol:-plot(u(x,t), t=10, x=0..10, size=[700,400]);  # bug
plots:-display
            ( sol:-plot
                      ( u(x,t),
                         t=10,
                         x=0..10
                      ),
                     size=[700,400]
           );
plots:-display
           (  [ seq
                 ( sol:-plot
                           ( u(x, t),
                              t = j,
                              x = 0 .. 10
                           ),
                    j = 1..10
                 )
              ],
              size = [700, 400],
              insequence = true
          )

in my earlier response

The only maple code you can run in a console window is a plaintext file (in Maple_Speak, this would be a .mpl file).

Forget any idea of running a .mw or .mws file in a console window - it is never going to happen

Generally speaking it is not too difficult to convert a .mw.mws file to .mpl format, although a decent text editor may be required. Once you create the .mpl file, then follow the instructions in my previous post.

If you don't know how to convert the .m/.mws file to .mpl, then I can only suggest that yu upload the former here, and sone kind soul may do it for you

Since Maple 7 was superseded sixteen years ago, and I no longer have access, you'd probably be better reading the help page, becasue  I have to guess

The obvious suggestions are either

  1. omit the variable to be solved for, or
  2. if you wish to supply the variable(s), then supply it/them as a list

see my notes below

 

restart;
#solve([x+3=y,x+z=6,x+y+z=10],x,y,z);

well the above definitely will not work (doesn't work in Maple 2018 either!), but solve([x+3=y,x+z=6,x+y+z=10],[x,y,z]) ought to (It doess in more recent Maple versions

 


#solve([[x+3-y=0,2*x-y+2=0],x,y);

this won't work (doesn't work in Maple 2018 either!) because you have unbalanced '[' brackets, and again I think that the unknowns should be supplied as a list, as in solve([x+3-y=0,2*x-y+2=0],[x,y]);
 


#solve([x-3=0],x);
#
#...but Maple can solve this one!
solve(x-3=0,x);

Try this  solve(x-3=0,[x])  or this solve(x-3=0) or this solve([x-3=0],[x])

@das1404 

" Maple 7 does not have the provision in the seq command to increment by floating point values"

No way I can verify this: Maple 7 was superseded in April 2002 - as in 16 years ago. I just don't have any Maple releases which are that old.

The attached does exactly the same as the original, except with integer values in the seq() command

restart;
with(plottools):
with(plots):
numFrames:=50:
l1:=line( [0,0], [0,1]):
l2:=line( [0,1], [-t/numFrames,1]):
l3:=line( [0,1], [ t/numFrames,1]):
l4:=line( [-t/numFrames,1], [-1,2]):
l5:=line( [t/numFrames,1], [1,2]):
d:=display([l1,l2,l3, l4, l5], color=red, thickness=6):
display(seq( d, t=0..numFrames), insequence=true, axes=none);

 

 


Download morph2.mw

 

 

@Bosco Emmanuel 

See the wroksheet belo

#
# Original example
#
  restart;
  kernelopts(version);
  solution := {p[1] = 2.788944999, p[2] = 4.940143518}, { p[1] = 15.29764736, p[2] = 4.946617373};
  M1:=Matrix(convert~([solution], list));
  M2:=rhs~(Matrix((convert~([solution], list))));

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

 

solution := {p[1] = 2.788944999, p[2] = 4.940143518}, {p[1] = 15.29764736, p[2] = 4.946617373}

 

Matrix(2, 2, {(1, 1) = p[1] = 2.788944999, (1, 2) = p[2] = 4.940143518, (2, 1) = p[1] = 15.29764736, (2, 2) = p[2] = 4.946617373})

 

Matrix(%id = 18446744074332167934)

(1)

#
# Op's second example
#
  restart;
  solution := {p[1] = 2.788944999, p[2] = 4.940143518};
  M1 := Matrix(convert~([solution], list));
  M2 := rhs~(Matrix(convert~([solution], list)));

solution := {p[1] = 2.788944999, p[2] = 4.940143518}

 

Vector[row](2, {(1) = p[1] = 2.788944999, (2) = p[2] = 4.940143518})

 

Matrix(%id = 18446744074333717438)

(2)

 


 

Download toMat.mw

Use the above link to download/run it

if one changes 'floor' to trunc, as in

 restart;
  f:=x->1-2*(1/x-trunc(1/x))+1/x;
  x:=50100;
  A:=Array(0..20):
  for j from 1 to 100000 do
        tmp:= f(x);
        p:= trunc(evalf(tmp));
        A[p]:= A[p]+1;
        x:=tmp
  od:
  A;

 

The code I supplied

  1. iterates the sequence x=f(x)
  2. it generates the floor(), so for example, 3.1234567, will become 3
  3. having generated the floor, the corresponding entry in the Array A will be incremented by 1, so for exmaple A[3} will become A[3]+1

The effect of this algorithm is that

A[0] containes the count for values in the range 0..1

A[1] containes the count for values in the range 1..2

and so on. As I explained before, the iteration sequence will return values in all ranges from 0..1, up to 16..17. Hence all entries in the array from A[0] to A[16] are non-zero

 

to generate a "block" matrix from a list of sub-matrices is with LinearAlgebra:-DiagonalMatrix(), as in the following "toy" example

with(LinearAlgebra):
A:= [seq( RandomMatrix(2,2), j=1..3)];
DiagonalMatrix(A);

The sub-matrices, don't evan have to be the same size - check the help for  DiagonalMatrix()

Before I do that I'd just like to thank Sergey Moiseev  for providing the DirectSearch package in the first place. Also for taking the time to comment on this thread

I learned a couple of things about DirectSearch while working on this problem

  1. I was unaware that, that I could set Allsolutions=true and follow it with some kind of "sub-option" like solutions=1, or solutions=2. I don't think this sub-option is documented anywhere, but it is very useful
  2. As I explained in my previous responses, the OP's problem has two valid solutions, since the cardioid always intercepts the y-axis in two places - the trick is to pick the one which results in the positive y-intercept. In an earlier response I stated

The third execution group uses DirectSearch() with limited constraints and the option AllSolutions=true, solutions=2. This returns both solutions for one angle in 1.8sec. So about 60X slower than the fsolve() process in (2) above - and I still have the overhead of figuring out which of the two returned solution is valid. This overhead would be minimal, so I'm not even going to count it.

Now this is the method which Sergey adopted in his worksheet: ie generate two solutions and then use some additional code to determine which of these two possibilities results in the positive y-intercept.

However as I stated in the same post, it is possible to achieve the same result directly, by supplying the requirement for a positive y-intercept as an additional constraint to the DirectSearch:-Solveequations()  command.

Theonly problem is that adding the "positive y-intercept" constraint to the DirectSearch:-SolveEquations() command, increases the solution time for one angle from 1.8secs to 47.5secs. I really don't think this is reasonable. If I can generate both solution in 1.8secs, I'm pretty sure I could check which gives a positive y-intercept in <0.1sec - it is just two expression evaluations. So why does the exectuuon time explode if I add the positive y-intercept requirement as a constrain with the DirectSeacrh:SolveEquations command? This I really don't get!

First 98 99 100 101 102 103 104 Last Page 100 of 207