tomleslie

5323 Reputation

15 Badges

9 years, 271 days

MaplePrimes Activity


These are answers submitted by tomleslie

that the code you present is basically unfixable. Now just becuase I like making guesses, I'm going to make the following observations/recommendations

  1. learn the difference between a function with an argument nad an indexed variable: for example x(0) is the function x() with the argument 0, x[0] is the zeroth element of indexable variable 'x'. These are two entirely different concepts.  If you don't understand the difference, then don't write any code until you do!
  2. learn the difference between an indexable quantity (eg x[0]) and one with an inert subscript (eq x__0). If you choose to use Maple's 2D input option then this will "appear" the same in both input and output lines - although, of course, they have entirely different meanings. If you don't understand the difference, then don't write any code until you do!
  3. don't use the same name as the index variable in a "for" loop and then as the index variable in any statement (eg add() ) within that "for" loop. You *might* get away with this ( Maple's scoping rules are pretty good), but it is a high-risk activity.
  4. don't try to define a variable in terms of itself - for example in your code you have various places where you write something like x[n+1]=add(x[n], n=0..m). Note that this violates recommendation (3) above, but let's just assssume for the moment that Maple's scoping rules will handle this, and that the two quantities labelled 'n' on either side of this assignment are entirely distinct - so that (for example) Maple will (may?) interpret this as x[2]=add(x[n], n=0..m). Consider what happens if n=2 on the lhs and m=2. Then the statement becomes x[2]:=x[0]+x[1]+x[2]. So you are trying to assign x[2] in terms of itself. This is known as "recursive assignment" and will never work.
  5. If I guess what you actually mean when you commit any/all the errors above and try to fix it then I will get something like the attached. (I have also assumed that when you defined the parmeter 'u' and then never used it, you actually meant the parameter 'mu' which is used but never defined - of course this could be one of the many guesses where I'm wrong

Anyhow for what it is worth, the attached *might* be of some use - but you will have to check every single guess I have made

restart;
m := 10;
S[lambda] := sum(S[b]*lambda^b, b=0..m):
L[lambda]:= sum(L[b]*lambda^b, b=0..m):
G[lambda]:= S[lambda]*L[lambda]:
ft := unapply(G[lambda], lambda):
for i from 0 to m do
    A1[i] := (D@@i)(ft)(0)/i!;
end do;

10

 

S[0]*L[0]

 

L[0]*S[1]+L[1]*S[0]

 

L[0]*S[2]+L[1]*S[1]+L[2]*S[0]

 

L[0]*S[3]+L[1]*S[2]+L[2]*S[1]+L[3]*S[0]

 

L[0]*S[4]+L[1]*S[3]+L[2]*S[2]+L[3]*S[1]+L[4]*S[0]

 

L[0]*S[5]+L[1]*S[4]+L[2]*S[3]+L[3]*S[2]+L[4]*S[1]+L[5]*S[0]

 

L[0]*S[6]+L[1]*S[5]+L[2]*S[4]+L[3]*S[3]+L[4]*S[2]+L[5]*S[1]+L[6]*S[0]

 

L[0]*S[7]+L[1]*S[6]+L[2]*S[5]+L[3]*S[4]+L[4]*S[3]+L[5]*S[2]+L[6]*S[1]+L[7]*S[0]

 

L[0]*S[8]+L[1]*S[7]+L[2]*S[6]+L[3]*S[5]+L[4]*S[4]+L[5]*S[3]+L[6]*S[2]+L[7]*S[1]+L[8]*S[0]

 

L[0]*S[9]+L[1]*S[8]+L[2]*S[7]+L[3]*S[6]+L[4]*S[5]+L[5]*S[4]+L[6]*S[3]+L[7]*S[2]+L[8]*S[1]+L[9]*S[0]

 

L[0]*S[10]+L[1]*S[9]+L[2]*S[8]+L[3]*S[7]+L[4]*S[6]+L[5]*S[5]+L[6]*S[4]+L[7]*S[3]+L[8]*S[2]+L[9]*S[1]+L[10]*S[0]

(1)

beta:= 0.04: lambda:= 0.4: delta:= 0.3:
d:= 0.01: e:= 0.1: a:= 0.2: k:= 0.6:
mu:= 0.03: q:= 0.8:
x[0]:= 9: w[0]:= 3: y[0]:= 1: v[0]:= 4:
m := 3:

for n from 0 to m do
    x[n+1]:= x[0]+lambda*t-d*int(add(x[jj], jj=0..n), t=0..t)
             -
             beta*int(add(x[jj], jj=0..n)*x[n]*v[n], t=0..t);
    w[n+1]:= w[0]+(1-q)*beta*int(add(x[jj]*v[jj], jj=0..n), t=0..t)
             -
             e*int(add(w[jj], jj=0..n), t=0..t)
             -
             delta*int(add(w[jj], jj=0..n), t=0..t);
    y[n+1]:= y[0] + q*beta*int(add(x[jj]*v[jj], jj=0..n), t=0..t)
             -
             a*int(add(y[jj], jj=0..n), t=0..t)
             +
             delta*int(add(w[jj], jj=0..n), t=0..t);
    v[n+1]:= v[0] + k*int(add(y[jj], jj=0..n), t=0..t)
             -
             mu*int(add(v[jj], jj=0..n), t=0..t);
end do

9-12.65*t

 

3-.912*t

 

1+1.852*t

 

4+.48*t

 

9-25.70*t+25.83205000*t^2-.7681080000*t^4-6.348613332*t^3

 

3-1.824*t-0.1619200000e-1*t^3-0.272000000e-2*t^2

 

1+3.704*t-0.6476800000e-1*t^3-1.062480000*t^2

 

4+.96*t+.5484000000*t^2

 

9-38.75*t+78.65015000*t^2-90.72568551*t^3-27.42089744*t^5+62.64846853*t^4-0.1176547131e-2*t^11-0.2365939406e-1*t^10-0.5361510560e-1*t^9+.5664253416*t^8-1.763510425*t^7+7.623064696*t^6

 

3-2.736*t-0.4814062025e-3*t^7-0.5625284308e-2*t^6+0.7998712674e-2*t^5-0.2775993066e-1*t^4+.2070821333*t^3-0.145600000e-1*t^2

 

1+5.556*t-0.1925624810e-2*t^7-0.2250113723e-1*t^6+0.3199485070e-1*t^5-.1154925226*t^4+.8974378666*t^3-3.213040000*t^2

 

4+1.44*t+1.645200000*t^2-0.9715200000e-2*t^4-.2179800000*t^3

 

9-51.80*t+0.1992354573e-10*t^27+0.1296329103e-8*t^26+0.2643535147e-7*t^25+0.1127183443e-6*t^24-0.1989329580e-5*t^23-0.1355710429e-4*t^22+0.5938710560e-4*t^21+0.9247798360e-4*t^20-0.1107326654e-2*t^19+0.9847756904e-2*t^18-0.6836658000e-1*t^17+.3297720939*t^16-1.291286981*t^15+4.458073772*t^14-13.55133255*t^13+35.62626141*t^12-80.62369489*t^11+158.4926548*t^10-273.6418403*t^9+416.1169516*t^8-554.3659409*t^7+638.9342751*t^6-625.6821295*t^5+508.0768001*t^4-327.8484020*t^3+158.1663000*t^2

 

3-3.648*t+0.5715195343e-8*t^16+0.2593703940e-6*t^15+0.2138571915e-5*t^14-0.2119050938e-4*t^13-0.1555465514e-3*t^12+0.7784654894e-3*t^11-0.2956329137e-2*t^10+0.1567669086e-1*t^9-0.5394031369e-1*t^8+.1290831356*t^7-.2534910499*t^6+.4225449502*t^5-.6791878360*t^4+.9386432000*t^3-0.355200000e-1*t^2

 

1+7.408*t+0.2286078137e-7*t^16+0.1037481576e-5*t^15+0.8554287661e-5*t^14-0.8476203750e-4*t^13-0.6221862058e-3*t^12+0.3113861958e-2*t^11-0.1182531655e-1*t^10+0.6270676342e-1*t^9-.2158274481*t^8+.5154485692*t^7-1.012497769*t^6+1.684250728*t^5-2.667712024*t^4+4.028663467*t^3-6.451680000*t^2

 

4+1.92*t+3.290400000*t^2+.1265353300*t^4-.8770399998*t^3-0.1444218607e-3*t^8-0.1928668906e-2*t^7+0.3199485070e-2*t^6-0.1380081151e-1*t^5

(2)

``

Download adom.mw

of which the attached is only one

  restart;
  with(plots):
  with(plottools):
  d1:= display
       ( [ display
           ( circle
             ( [-6,0],
               6,
               color=red,
               thickness=2
             )
           ),
           plot( 6*sin(x),
                 x=0..4*Pi,
                 color=red,
                 thickness=2
               )
         ]
       ):
  F:= proc(t)
           display
           ( [ display
               ( line
                 ( [-6,0],
                   [6*cos(t)-6, 6*sin(t)],
                   color=blue,
                   thickness=4
                 )
               ),
               pointplot
               ( [t, 6*sin(t)],
                 symbol=solidcircle,
                 symbolsize=24,
                 color=blue
               )
             ],
             scaling=constrained
           );
      end proc:
   animate( F, [theta], theta=0..4*Pi, background=d1, frames=100);
        

 

 

Download anim.mw

 

but if I were trying to achieve the same(?) thing, I'd probably wirte the attached - which *seems* to work

  p:= proc()
           local x:=1,
                 v:= <x>;
           return v;
      end proc;
  ans:=p();

p := proc () local x, v; x := 1; v := `<,>`(x); return v end proc

 

Vector[column](%id = 18446744074399490766)

(1)

 

Download oddProc.mw

 

It is not too difficult to "reproduce" the calculation in the paper you reference, which is done in the attached

  restart;
  interface(version);

`Standard Worksheet Interface, Maple 2019.1, Windows 7, May 21 2019 Build ID 1399874`

(1)

#
# Set up system for the paper supplied by the OP.
# The two "important equations in that paper are
# numbered eq1 and eq37 - so use the same labelling here
#
  eq1:=v__beta(r,beta)=2*R__i^2*(R(beta)^2-r^2)/R(beta)^4;
  eq37:=diff(v__r(r, theta, beta),r)*r*(R__f-r*cos(theta))+v__r(r,theta,beta)*(R__f-2*r*cos(theta))+r*diff(v__beta(r,beta),beta)=0;
#
# According to the text eq1 is subject to the additional
# condition that
#
# R(beta)=R__i+2*beta*(R__f-R__i)/Pi
#
# so make this substitution in eq1
#
  eq0:=R(beta)=R__i+2*beta*(R__f-R__i)/Pi;
  eq1a:= subs(eq0, eq1);
#
# Then susbtitute this result in eq37 to produce the
# "ordinary linear first-order differetnial equation"
#
  eq37a:=simplify(expand(subs(eq1a, eq37)));

v__beta(r, beta) = 2*R__i^2*(R(beta)^2-r^2)/R(beta)^4

 

(diff(v__r(r, theta, beta), r))*r*(R__f-r*cos(theta))+v__r(r, theta, beta)*(R__f-2*r*cos(theta))+r*(diff(v__beta(r, beta), beta)) = 0

 

R(beta) = R__i+2*beta*(R__f-R__i)/Pi

 

v__beta(r, beta) = 2*R__i^2*((R__i+2*beta*(R__f-R__i)/Pi)^2-r^2)/(R__i+2*beta*(R__f-R__i)/Pi)^4

 

(-(r*cos(theta)-R__f)*((Pi-2*beta)*R__i+2*beta*R__f)^5*r*(diff(v__r(r, theta, beta), r))-2*(r*cos(theta)-(1/2)*R__f)*((Pi-2*beta)*R__i+2*beta*R__f)^5*v__r(r, theta, beta)+16*(R__f-R__i)*Pi^2*R__i^2*(-(1/2)*(Pi-2*beta)^2*R__i^2-2*R__f*beta*(Pi-2*beta)*R__i+r^2*Pi^2-2*beta^2*R__f^2)*r)/((Pi-2*beta)*R__i+2*beta*R__f)^5 = 0

(2)

#
# Solve the above differential equation
#
  sol1:=simplify(dsolve(eq37a, v__r(r, theta,beta)));
#
# The solution contains an arbirary function
# _F1(theta, beta) in the "undifferentiated" variables
# so I am arbitrarily(?) going to set this function to 0
#
  sol2:=eval(sol1, _F1(theta, beta)=0);

v__r(r, theta, beta) = (((Pi-2*beta)*R__i+2*beta*R__f)^5*_F1(theta, beta)+4*(R__f-R__i)*Pi^2*R__i^2*((-Pi+2*beta)*R__i+r*Pi-2*beta*R__f)*r^2*((Pi-2*beta)*R__i+r*Pi+2*beta*R__f))/((r*cos(theta)-R__f)*((Pi-2*beta)*R__i+2*beta*R__f)^5*r)

 

v__r(r, theta, beta) = 4*(R__f-R__i)*Pi^2*R__i^2*((-Pi+2*beta)*R__i+r*Pi-2*beta*R__f)*r*((Pi-2*beta)*R__i+r*Pi+2*beta*R__f)/((r*cos(theta)-R__f)*((Pi-2*beta)*R__i+2*beta*R__f)^5)

(3)

#
# The above solution *looks* very similar to the desired
# solution (labelled eq2 in the OP's reference paper), but
# trying to massage sol2 above to exactly match the form
# the form given in the paper could take for ever!
#
# Easier just to reproduce eq2 (from the paper) here
#
  eq2:=v__r(r, theta, beta)=4*Pi^2*r*(R__f-R__i)*R__i^2*((Pi*R__i+2*(R__f-R__i)*beta)^2-Pi^2*r^2)/((Pi*R__i+2*(R__f-R__i)*beta)^5*(R__f-r*cos(theta)));

v__r(r, theta, beta) = 4*Pi^2*r*(R__f-R__i)*R__i^2*((Pi*R__i+2*(R__f-R__i)*beta)^2-r^2*Pi^2)/((Pi*R__i+2*(R__f-R__i)*beta)^5*(R__f-r*cos(theta)))

(4)

#
# Check that the right hand side of the ODE solution above
# and eq2 (from the paper) are the same, by subtracting them.
#
# Answer should be zero!
#
  simplify(rhs(sol2)-rhs(eq2));

0

(5)

#
# Knowing that the solution obtaine by dsolve() above is
# "correct", OP's original worksheet wants to compute
# this for some given values of parameters
#
  d:=10: c:=10: LI:=4: R__i:=d/2+LI: R__f:=c+d/2+LI:
#
# so that the solution sol2 becomes
#
  sol2;

v__r(r, theta, beta) = 3240*Pi^2*(Pi*r-9*Pi-20*beta)*r*(Pi*r+9*Pi+20*beta)/((r*cos(theta)-19)*(9*Pi+20*beta)^5)

(6)

 

Download folode2.mw

Maple18, Maple 2015, and Maple 2016 all return "infinity"

Maple 2017, Maple 2018 and Maple 2019 all returrn Pi*R

Looking at the "updates" in Maple 2017 (see ?Advanced Math), there is a whole section on improvements associated with symbolic integration. So I guess whatever the original problem, one of these updates fixed it.

do a contour plot of a vector field, since the former is magnitude-only and the latter contains both magnitude and direction. You can produce a contour plot of the magnitude of the vector field, which is what I have done in the attached

  restart;
  with(VectorCalculus):
  with(plots):
  epsilon:=.01:
#
# Define the potential and plot it
#
  pot := 1/sqrt(x^2+y^2+epsilon)-1/sqrt((x-.25)^2+y^2+epsilon):
  contourplot(pot, x=-0.5..1, y=-0.5..0.5, grid=[100,100]);
#
# Take the gradient of the potential - which should be the
# electric field
#
  v := VectorField( Gradient( pot, [x,y] ), 'cartesian'[x,y] ):
#
# Produce a field plot
#
  fieldplot(v, x=-0.5..0.5, y=-0.5..0.5, arrows=THICK, color=red, anchor=tail);
#
# OP wants a contour plot of the electric field. However
# a contour plot is magnitude-only. Presumably OP wants the
# contour plot to represent the purely the magnitude of the
# vector field
#
  contourplot(Norm(v)(<x,y>), x=-0.5..1, y=-0.5..0.5, grid=[100,100]);

 

 

 

 


 

Download contplot.mw

which I *think* I have fixed in the attached. This involved removing lots of redundant stuff and a fair amount of editing so the chances that I got everything correct is not that great. I suggest you read/check this very carefully
 

For some reasom this site is not displaying worksheets correctly today, so you will have to download/execute

someODEs.mw

the attached will calculate/plot both speed() and L() for any numeric argument.

Unfortunately the MApleprimes uploader sppears to be broken - again- and will not display the contents of this file on this site so you will have to download/execute

speedandL.mw

My ability to help is limited by the fact I only have a 'bare' copy of Matlab with no addOns/toolboxes, other than the Maple toolbox. However the following observations may be helpful

From the Matlab 'HOME' tab, Add-Ons -> Manage AddOns does not identify the Maple toolbox as a conventional add-on. In fact it does not appear in this list at all. Suggests that one cannot use Matlab'x Add-On manager

On the other hand, from the Matlab 'HOME' tab Set Path shows two Maple-related entries, in my case at the bottom of the list. These entries are

C:\Program Files\MATLAB\R2019b\toolbox\maple
C:\Program Files\MATLAB\R2019b\toolbox\maple\util

So I *assume* that when one installs the Maple toolbox, the Matlab default pathdef.m file (located in C:\Program Files\MATLAB\R2019b\toolbox\local for a "default" installation) is edited to include these "Maple-related" entries. Presumably also, during the Maple toolbox installation, references to the "default" Matlab symbolic toolbox are removed from the pathdef.m file.

So the first thing experiment I would try

  1. Uninstall the Maple toolbox
  2. Verify that the default symbolic toolbox is working
  3. Copy the pathdef.m file to somewhere convenient
  4. Reinstall the Maple toolbox
  5. In a decent editor check the differences between the "current" pathdef.m file and that saved at step (3) above. They *ought* to be different - references to the default symbolic toolbox removed and references to Maple included
  6. At this stage (ie with the Maple toolbox installed and "active"), use the Matlab toolbar HOME->Set Path dialogue to remove the two Maple entries
  7. Path changes take place "immediately" (ie no restart is necessary), this ought to disable the Maple toolbox (without "unistalling" it
  8. Assuming that everything has worked until now find the references to the defalt symbolic toolbox obtained at step 5) above, and again using the HOME->Set Path dialogue, use the Add folder option to reinstate these.
  9. Verify that the default symbolic toolbox is now working
  10. Again assuming that everything is OK, you can now "toggle" beween default and Maple symbolic toolboxes just by using the Add Folder and Remove Folder options in the Set Path dialogue

As has already been noted it is not clear whether you mean 12^(6^5), or (12^6)^5.  The attached does both

  restart:

  doWork:=proc( N::posint)
                local p,
                      num:=N,
                      digsum:=add
                              ( irem
                                (num, 10, 'num'),
                                p=1..length(num)
                              );
                if   irem(digsum, 3)=0
                then printf( "      %a is divisible by 3\n", digsum):
                elif isprime(digsum)
                then printf( "      %a is prime\n", digsum):
                else printf( "      %a is nether prime nor divisible by 3\n")
                fi:
          end proc:
  doWork(12^(6^5));
  doWork((12^6)^5);

      37845 is divisible by 3
      153 is divisible by 3

 

 

 

Download factor.mw

 

You can't use Maple's in-built numeric solver when you have three boundary conditions on the same dependent variable - you have Z(0)=1, Z(1)=exp(1) and Z(3/4)=exp(3/4). In the attached I have used a simple "shooting method" approach to convert the last of these conditions into an additional condition at x=0, by generating an appropriate value for  D[1$2](Z)(0).

Once this has been obtained then you can use Maple's dsolve() with the 'numeric' option to obtain the desired(?) solution

Check the attached

  restart:
  f:= 0:
  Y:= 1+x-58/9*x^2-3*x^2*exp(1)+64/9*x^2*exp(3/4)+40/9*x^3+4*x^3*exp(1)-64/9*x^3*exp(3/4):
  odesys:= [ diff(Z(x), x$4) = 0.001*diff(Y, x$4)+0.999*(f+exp(-x)*Y*Y),
             Z(0) = 1, Z(1)=exp(1),  D(Z)(0) = 1, D[1$2](Z)(0) = icVal]:
  getSol:= proc( alpha )
                 global odesys:
                 if   type(alpha, numeric)
                 then return evalf
                             ( rhs
                               ( dsolve
                                 ( eval
                                   ( odesys,
                                     icVal=alpha
                                   ),
                                   numeric
                                 )(3/4)[2]
                               )-exp(3/4)
                             );
                 else return procname(alpha)
                 fi;
           end proc:
#
# Generate the value for  D[1$2](Z)(0) which will
# "replicate" the BC Z(3/4)=exp(3/4), then solve the
# resulting system
#
  ans:=fsolve( getSol, 0..2):
  sol:=dsolve( eval( odesys, icVal=ans), numeric):
#
# Plot the solution of the ODE with the modified boundary
# condition
#
  p1:= plots:-odeplot( sol, [x, Z(x)], x=0..1);
#
# Plot the difference between the ode solution
# and exp(x) - note that this difference is "zero"
# at x=3/4
#
  p2:= plots:-odeplot( sol, [x, Z(x)-exp(x)], x=0..1);
 

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(10, {(1) = .0, (2) = .1035522254865972, (3) = .24519828381296987, (4) = .3799478193552541, (5) = .503521952794316, (6) = .6168949604764327, (7) = .7212797883990792, (8) = .8185224087372147, (9) = .9105143600838255, (10) = 1.0}, datatype = float[8], order = C_order); Y := Matrix(10, 4, {(1, 1) = 1.0, (1, 2) = 1.0, (1, 3) = .9997284814, (1, 4) = 1.0015789187052664, (2, 1) = 1.109102546816479, (2, 2) = 1.1090838585077165, (2, 3) = 1.1089893945652205, (2, 4) = 1.1105455559517092, (3, 1) = 1.2778701868777473, (3, 2) = 1.2778519409240123, (3, 3) = 1.277938440568671, (3, 4) = 1.2788925273345446, (4, 1) = 1.4622016746038597, (4, 2) = 1.4622014989325756, (4, 3) = 1.4623657325593096, (4, 4) = 1.462544901925881, (5, 1) = 1.6545320253726457, (5, 2) = 1.6545516203064088, (5, 3) = 1.6546924109083185, (5, 4) = 1.6541483740612573, (6, 1) = 1.8531611239783727, (6, 2) = 1.8531919754946065, (6, 3) = 1.8532400609541102, (6, 4) = 1.852184217653946, (7, 1) = 2.057063333053156, (7, 2) = 2.0570928910924984, (7, 3) = 2.057015669943291, (7, 4) = 2.0557095628937962, (8, 1) = 2.2671489949882484, (8, 2) = 2.2671647468270337, (8, 3) = 2.2669574840472175, (8, 4) = 2.265617142608862, (9, 1) = 2.4856028360355884, (9, 2) = 2.485593935859521, (9, 3) = 2.485266381188787, (9, 4) = 2.4839977477406534, (10, 1) = 2.71828182845905, (10, 2) = 2.7182386065361217, (10, 3) = 2.7177993410540364, (10, 4) = 2.716544491925582}, datatype = float[8], order = C_order); YP := Matrix(10, 4, {(1, 1) = 1.0, (1, 2) = .9997284814, (1, 3) = 1.0015789187052664, (1, 4) = .999, (2, 1) = 1.1090838585077165, (2, 2) = 1.1089893945652205, (2, 3) = 1.1105455559517092, (2, 4) = 1.107233907146643, (3, 1) = 1.2778519409240123, (3, 2) = 1.277938440568671, (3, 3) = 1.2788925273345446, (3, 4) = 1.273716128797201, (4, 1) = 1.4622014989325756, (4, 2) = 1.4623657325593096, (4, 3) = 1.462544901925881, (4, 4) = 1.4564700734019, (5, 1) = 1.6545516203064088, (5, 2) = 1.6546924109083185, (5, 3) = 1.6541483740612573, (5, 4) = 1.6487782312719357, (6, 1) = 1.8531919754946065, (6, 2) = 1.8532400609541102, (6, 3) = 1.852184217653946, (6, 4) = 1.8486835183090522, (7, 1) = 2.0570928910924984, (7, 2) = 2.057015669943291, (7, 3) = 2.0557095628937962, (7, 4) = 2.0544306500099254, (8, 1) = 2.2671647468270337, (8, 2) = 2.2669574840472175, (8, 3) = 2.265617142608862, (8, 4) = 2.2660572971002355, (9, 1) = 2.485593935859521, (9, 2) = 2.485266381188787, (9, 3) = 2.4839977477406534, (9, 4) = 2.4848304338285216, (10, 1) = 2.7182386065361217, (10, 2) = 2.7177993410540364, (10, 3) = 2.716544491925582, (10, 4) = 2.715563546630516}, 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(10, {(1) = .0, (2) = .1035522254865972, (3) = .24519828381296987, (4) = .3799478193552541, (5) = .503521952794316, (6) = .6168949604764327, (7) = .7212797883990792, (8) = .8185224087372147, (9) = .9105143600838255, (10) = 1.0}, datatype = float[8], order = C_order); Y := Matrix(10, 4, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = 0.15174185478711788e-7, (2, 1) = -0.20259265106448437e-9, (2, 2) = 0.8184857433913237e-10, (2, 3) = 0.15700986201749992e-8, (2, 4) = 0.15173052815765837e-7, (3, 1) = -0.7454669674564436e-9, (3, 2) = 0.4616826296409464e-9, (3, 3) = 0.37125208110290578e-8, (3, 4) = 0.15171897592267647e-7, (4, 1) = -0.11247059311640284e-8, (4, 2) = 0.1103849487456392e-8, (4, 3) = 0.57516164716630034e-8, (4, 4) = 0.15173880200643165e-7, (5, 1) = -0.12977351049586068e-8, (5, 2) = 0.19330216455853525e-8, (5, 3) = 0.7622879934494e-8, (5, 4) = 0.15175083684087017e-7, (6, 1) = -0.12958729257339628e-8, (6, 2) = 0.28963748328144248e-8, (6, 3) = 0.9340817724486851e-8, (6, 4) = 0.1517549632148347e-7, (7, 1) = -0.11472396637035051e-8, (7, 2) = 0.39551106747826225e-8, (7, 3) = 0.10923400363554895e-7, (7, 4) = 0.1517554413889154e-7, (8, 1) = -0.8748252483861432e-9, (8, 2) = 0.5089774530152374e-8, (8, 3) = 0.12398199661631365e-7, (8, 4) = 0.15175461093085685e-7, (9, 1) = -0.4920486832962509e-9, (9, 2) = 0.6295037547047582e-8, (9, 3) = 0.13793650783357036e-7, (9, 4) = 0.15175340432771107e-7, (10, 1) = .0, (10, 2) = 0.7590588996645805e-8, (10, 3) = 0.15151223114671366e-7, (10, 4) = 0.15175200116094352e-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[10] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(1.517554413889154e-8) elif outpoint = "errorproc" then error "this is already the error procedure" elif outpoint = "rawdata" then return [4, 10, [Z(x), diff(Z(x), x), diff(diff(Z(x), x), x), diff(diff(diff(Z(x), x), x), x)], X, Y] else return ('procname')(x_bvp) end if end if; if outpoint < X[1] or X[10] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[10] end if; V := array([1 = 4, 2 = 0]); if Digits <= trunc(evalhf(Digits)) then L := Vector(4, 'datatype' = 'float'[8]); yout := Vector(4, 'datatype' = 'float'[8]); evalhf(`dsolve/numeric/lagrange`(10, 4, X, Y, outpoint, var(yout), var(L), var(V))) else L := Vector(4, 'datatype' = 'sfloat'); yout := Vector(4, 'datatype' = 'sfloat'); `dsolve/numeric/lagrange`(10, 4, X, Y, outpoint, yout, L, V) end if; [x = outpoint, seq('[Z(x), diff(Z(x), x), diff(diff(Z(x), x), x), diff(diff(diff(Z(x), x), x), x)]'[i] = yout[i], i = 1 .. 4)] 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[10] elif outpoint = "order" then return 6 elif outpoint = "error" then return HFloat(1.517554413889154e-8) elif outpoint = "errorproc" then return eval(errproc) elif outpoint = "rawdata" then return [4, 10, "depnames", X, Y, YP] else error "non-numeric value" end if end if; if outpoint < X[1] or X[10] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[10] 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(4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8]); evalhf(`dsolve/numeric/hermite`(10, 4, 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(4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.}); `dsolve/numeric/hermite`(10, 4, X, Y, YP, outpoint, yout, L, V) end if; [outpoint, seq(yout[i], i = 1 .. 4)] end proc, (2) = Array(0..0, {}), (3) = [x, Z(x), diff(Z(x), x), diff(diff(Z(x), x), x), diff(diff(diff(Z(x), x), x), x)], (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); [x = res[1], seq('[Z(x), diff(Z(x), x), diff(diff(Z(x), x), x), diff(diff(diff(Z(x), x), x), x)]'[i] = res[i+1], i = 1 .. 4)] catch: error  end try end proc

 

 

 

 

 

NULL

Download shoot.mw

Maple and Matlab are two completely different software packages. This has a few consequences

  1. Code which runs in Maple will not run in Matlab
  2. Code which runs in Matlab will not run in Maple

The attached will run in Maple

  restart;
  j:= 500:      tp:= 0.07*j: Ap:= 0.25: Aq:= 0.3:     tq:= 0.03*j:
  tr1:= 0.05*j: Ar:= 2:      As:= 0.4:  tr2:= 0.04*j: ts:= 0.04*j:
  tt:= 0.17*j:  At:= 0.4:

  u1:= 0:
  u2:= (Ap/2)*(sin((2*Pi*t/tp)+(3*Pi/2))+1):
  u3:= 0:
  u4:= -(Aq/tq)*t:
  u5:= (((Ar+ Aq)/tr1)*t)-Aq:
  u6:= -(((Ar+ As)/tr2)*t)+Ar:
  u7:= ((As/ts)*t)- As:
  u8:= 0:
  u9:= (At/2)*(sin((2*Pi*t/tt)+(3*Pi/2))+1):
  u10:= 0:

  with(plots):
  display( [ plot(u1, t=1..0.1*j),
             plot(u2, t=1..tp),
             plot(u3, t=1..0.08*j),
             plot(u4, t=1..tq),
             plot(u5, t=1..tr1),
             plot(u6, t=1..tr2),
             plot(u7, t=1..ts),
             plot(u8, t=1..0.1*j),
             plot(u9, t=1..tt),
             plot(u10,t=1..0.08*j)
           ],
           view=[0..100,-1..3],
           axes=boxed
         );

 

 

Download doPlots.mw

that you actuallly do have the data as a matrix, then

ExportMatrix(fileName, matrixName)

ought to work.

To recall this information

M:=ImportMatrix(fileName)

will retrieve the matrix

is shown in the attached

  restart;
#
# Define a simple function called 'delta'
#
  delta:= (k::integer, r::integer)->`if`( k-r-1=0, 1, 0 ):
#
# A couple of examples
#
  delta(5,4);
  delta(5,3);

1

 

0

(1)

 

Download simpleFunc.mw

well

  1. In the first place I don't see why you are using spline fits, since the process you invoke is
    1. define a function
    2. plot the function
    3. extract data from the plot
    4. fit this data using splines to produce an approximation of the function which you already know at step (1) above
    5. use this approximate "fit" in subsequent calculations. Why????
    6. Hence I have removed all the spline fit stuff - it is pointless in the worksheet you supply
  2. You state that "in graph t=4000 my result is illogical". Actually no -it is entirely logical and has to to with the magnitudes of the functions h(x) and r(t) used in defining the boundary and initial conditions. The first of these is zero unless 5000<x<10000: within this range it never exceeds ~1.2*10-37 so could be considered very, very small with "little impact" on the overall PDE solution. On the other hand the initial condition C(0, t) = r(t) is identically zero for t<3600 and t>21600, but between these values, it gets very big, very quickly. For your first four plots, ie t= 2, 1000, 2000, 3000, C(0,t) is identically zero. For the case you find illogical (ie t=4000), the boundary condition evaluates to C(0,t)=2.88*10^7. I (for one) am not really surprised that when you move from a region where a boundary condition evaluates to 0, to one where the same boundary condition evaluates to 2.88*10^7 then one might expect a significant change in the PDE solution

More details are given in the comments in the attached

  restart;

  with(plots):
  with(plottools):
  with(CurveFitting):

  f:= x -> piecewise( 0 < x and x <= 5000, 0,
                      5000 < x and x <= 7500, 0.008*x - 40,
                      7500 < x and x <= 10000, -0.008*x + 80,
                      10000 < x and x <= 15000, 0
                    );
  Ic:=plot( f(x),
            x = 0 .. 15000,
            color = blue,
            legend = ["Initial Condition"],
            labels = ["x", "concentration"],
            axis = [tickmarks = [5, subticks = 1]]
          );

f := proc (x) options operator, arrow; piecewise(0 < x and x <= 5000, 0, 5000 < x and x <= 7500, 0.8e-2*x-40, 7500 < x and x <= 10000, (-1)*0.8e-2*x+80, 10000 < x and x <= 15000, 0) end proc

 

 

  g := t -> piecewise( 0 < t and t <= 3600, 0,
                       3600 < t and t <= 10800, t/240-15,
                       10800 < t and t <= 21600, -t/360+ 60,
                       21600 < t and t <= 36000, 0
                      );
  Bc:= plot( g(t),
             t = 0 .. 36000,
             color = green,
             legend = ["Boundary Condition"],
             labels = ["time(s)", "concentration"],
             axis = [tickmarks = [10, subticks = 1]]
           );

g := proc (t) options operator, arrow; piecewise(0 < t and t <= 3600, 0, 3600 < t and t <= 10800, (1/240)*t-15, 10800 < t and t <= 21600, -(1/360)*t+60, 21600 < t and t <= 36000, 0) end proc

 

 

  v := 0.5: alpha := 15: mu := (-v)/(2*alpha): beta := v^2/(4*alpha):
  h := x -> f(x)/exp(-mu*x):
  r := t -> g(t)/exp(-beta*t):
#
# As defined above the function f() has a maximum of of 20
# at x=7500. However at this x-value, the value of exp(-mu*x)
# as given by eval(exp(-mu*x), x=7500) will be 1.935576042*10^54
# so that the maximum value of the function h() will be h(7500)
# which comes out to be 1.033284127*10^(-53), which is pretty
# close to zero for all practical purposes
#
# Hence when the OP uses C(x, 0) = h(x) as a boundary condition,
# this is identically zero for x<5000 and x>10000. It is also
# very close to zero in the range 5000<x<10000. The value
# actually "peaks" at around 1.136946279*10^(-37) when x=~5060
# as can be seen in the first of the following plots
#
  plot(h(x), x=5000..10000);
#  
# As defined above the function g() has a maximum of 30, when
# t=10800. However the denominator exp(-beta*t) has a value of
# 2.862518552*10^(-20) at the same t-value. Hence the function
# r() is identically zero for t<3600 and t>21600. But somehere
# around t=10800, it becomes 30/2.862518552*10^(-20) or about
# 1.048028142*10^21. Since the denominator decreases exponentially
# as t increases the value of r() will continue to increase
# beyond the nominal maximum in the function g(), reaching a peak
# of about 2.9*10^38 somewhere around t=21350 as can be seen
# from the second of the following plots
#
  plot(r(t), t=3600..21600);

 

 

#
# Bearing in mind the range of values illustrated above for
# h(x) and r(t), consider the PDE and the BCs/ICs
#
# For any value of t<3600, the boundary condition C(0,t) is
# identically zero. Hence (roughly speaking) the values of
# C(x,t) for t=2,1000,2000, 3000, are governed mainly by the
# the form of the ODE and the BC C(x, 0) = h(x). Since h(x)
# is always "tiny" all of these solutions will be "tiny" as
# seen in the first plot below
#
# However for t>3600 (as in the plot case t=4000), the value
# of C(0,t)=r(t) becomes "huge" (r(4000)=2.88*0^7) with a
# consequent effect on the PDE solution as seen in the second
# plot below
#
  PDED := diff(C(x, t), t) = 15*diff(C(x, t), x, x):
  IBCD := C(x, 0) = h(x), C(0, t) = r(t), D[1](C)(15000, t) - mu*C(15000, t) = 0:
  pdsD := pdsolve(PDED, [IBCD], time = t, range = 0 .. 15000):
  display( [ pdsD:-plot(C(x,t), t = 2,    color = red),
             pdsD:-plot(C(x,t), t = 1000, color = blue),
             pdsD:-plot(C(x,t), t = 2000, color = green),
             pdsD:-plot(C(x,t), t = 3000, color = orange)
           ]
         );
  pdsD:-plot(C(x,t), t = 4000, color = black);

 

 

 

Download pdeProb.mw

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