tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are answers submitted by tomleslie

Fairly easy to get numerical values for the roots, although this obviously depends on the values you set for a1, b1, c1. See the attached

restart;
a1:=1: b1:=2: c1:=3:
s := BesselJ(1, alpha)+a1*BesselY(1, alpha)+b1*BesselJ(1, alpha)+c1*BesselK(1, alpha):
plot(s, alpha=0..20);
p:=unapply(s, alpha):
first:=0:
for i from 1 by 1 to 4 do
    first:=RootFinding:-NextZero(p, first);
od;
    

 

4.185492644

 

7.338621219

 

10.49638173

 

13.64610094

(1)

 

Download BessRoot.mw

Tried every way I know of doing a dot product in Maple 18, and can't generate any problems. See attached. Please upload worksheet which illustrates the issue


 

restart;
kernelopts(version);
Physics:-Version();
<1,1,1>.<2,2,2>;
A:=<1,1,1>:
B:=<2,2,2>:
A.B;
VectorCalculus:-DotProduct(A, B);
LinearAlgebra:-DotProduct(A, B);

`Maple 18.02, X86 64 WINDOWS, Oct 20 2014, Build ID 991181`

 

"C:\Program Files\Maple 18\lib\update.mla", `2014, October 21, 1:29 hours`

 

6

 

6

 

6

 

6

(1)

 


 

Download DP.mw

Depends a bit on whether the 'Re' in the y-axis label should be interpreted as Maple short-hand for 'Real', and therefor be printed as the ornate (rathe gothic) 'R' simple. I have gone with just printing "Re" without the interpretation as real part.
I have increased the labelfont and axisfont, to make the changes more obvious - you can decrease these to any values you want


The plot renders rather better within Maple than on this site
 

restart;

plot( [sin, cos],
       -Pi .. Pi,
       title = "Simple Trig Functions",
       legend = ["Sine Plot", "Cosine Plot"],
       titlefont = ["ARIAL", 15],
       labels = ["x values", typeset( r^2, "Re", C__f)],
       labeldirections = ["horizontal", "vertical"],
       labelfont = ["HELVETICA", 16],
       linestyle = [solid, longdash],
       axesfont = ["HELVETICA", "ROMAN", 16],
       legendstyle = [font = ["HELVETICA", 9], location = right],
       tickmarks=[ [ -Pi=-180^o, -2*Pi/3=-120^o, -Pi/3=-60^o,
                       0=`0`^o,     Pi/3=60^o,   2*Pi/3=120^o,
                      Pi=180^o
                   ],
                   default
                 ]
     )

 

 

 


 

Download plotLab.mw

 

When installing Maple you obviously do not have significant privilege to write to the directory /home/alon/MATLAB/R2018a/bin/matlab Two possibilities

  1. increase the permission level of whoever is runnng the Maple install process: eg run the install as 'root'. You should now have permission to write anything to anywhere
  2. decrease the permission level on the Matlab directory (use chmod), so that a 'user' running the Maple install has sufficient privilege to write to the Matlab directory. Check the 'Matlab' directory to see if it has user-write-privilege - if it doesn't, then use chmod on his directory to reduce its protection.
  3. As far as I can remember from UNIX days, if a directory (such as your matlab) only has root write privileges then no 'user' can change this. Only 'root' can. It would be pointless if a directory controlled by 'root' could have its privileges changed by 'user' so that any 'user' could make changes

the code shown in the attached. (NB the odds that I have correctly typed your function are probably no better than even - but this doesn't affect the method)


 

restart

#
# Define the function
#
  p:=t->1/(1+alpha__1*t+alpha__2*t^2)*( (893713/442368)*exp(-t)
                                        +
                                        (18431/9216)*exp(-t)*alpha__1*t
                                        -
                                        (451345/442368)*exp(-97*t)
                                        +
                                        (191/96)*exp(-t)*alpha__2*t^2
                                        -
                                        (9215/9216)*alpha__1*t*exp(-97*t)
                                        -
                                        (18145/9216)*exp(-t)*t
                                      )
       +
       1/(1+alpha__1*t+alpha__2*t^2)*( (-95/96)*alpha__2*t^2*exp(-97*t)
                                       -
                                       (95/96)*exp(-t)*alpha__1*t^2
                                       -
                                       (9025/9216)*alpha__1*t*exp(-97*t)
                                     ):

#
# By setting alpha__1 and alpha__2, generate
# vectors of values for the independent and
# dependent variable
#
  alpha__1:= 1: alpha__2:= 5:
  tVals:= Vector([seq(t, t=0..10)]):
  pVals:= Vector([ seq(evalf(p(t)), t=0..10)]):

  with(Statistics):
#
# Unassign the parameters alpha__1 and alpha__2
# because these are the values to be found!
#
  alpha__1:='alpha__1': alpha__2:='alpha__2':
#
# Use 'NonlinearFit' to generate values for the
# parameters. Hopefully(!) these will be very
# close to values used above for data generation,
# is alpha__1=1.0 and alpha__2=5
#
  NonlinearFit(p(t), tVals, pVals, t, output=parametervalues)

[alpha__1 = HFloat(1.0000000056100604), alpha__2 = HFloat(5.000000076629492)]

(1)

 


 

Download cFit.mw

  1. I'm not sure that I understand what you are trying to achieve
  2. If memory serves you are using a very early version of Maple (so there may be version issues)
  3. I split the code up into "manageable" chunks, just so that I could easily verify what is happening where. This also meant not running the code within a procedure
  4. I went through the result fixing places where warning and Error messages were occurring, and all of the code now executes, although there are many place where I don't really understand why you doing certain things
  5. Given the functional attached code - what is you problem?


 

restart;
#interface( verboseproc = 0 );
#printlevel:=5:
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
#   Letter R - attempting to put animation on stalk, but
#   have lost output when printlevel <4
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

with(plots):
with(plottools):
#with(CurveFitting):
#Letter R
#makeR:=proc(x0,y0,h,base, w )
x0:=0:y0:=0:h:=12:base:=5.9:w:=1.55:
#local a,opts, R1,R2,upR,Rrado,Rradi,col, r1,r2,nframes,i,framR,l1,stalkR, AS,x, x1,y1,x2,y2,CS, lin1, val1, pl1:
col:=`grey`:
opts:=scaling=constrained, style=patchnogrid,color=col:
l1:=w/2:
Rrado:=base-w-l1:
Rradi:=Rrado-w:
R1:=ellipticArc([x0+w+l1,y0+h-Rrado],Rrado,Rrado,-Pi/2..Pi/2,opts):
R2:=ellipticArc([x0+w+l1,y0+h-Rrado],Rrado-w,Rrado-w,-Pi/2..Pi/2,scaling=constrained):


 

#Upright
#upR:=rectangle([x0,y0+h], [x0+w,y0],filled=true, opts):
#upR:=rectangle([x0,y0+h], [x0+w,y0], opts):
upR:=rectangle([x0,y0+h], [x0+w,y0]):
r1:=rectangle([x0+w,y0+h], [x0+w+l1,y0+h-w]):
r2:=rectangle([x0+w,y0+h-w-2*Rradi], [x0+w+l1,y0+h-2*Rrado]):
#l1:=line([x0+base-w, y0+Rrado],[x0+base,y0+Rrado], color=col):

#stalkR is the 'stalk', or base-diagonal of the letter R
stalkR:=polygon([[x0+base-w,y0],[x0+w+l1, y0+h-2*Rrado],[x0+w+l1+w, y0+h-2*Rrado+w/4],[x0+base,y0]], color=col):

#Calclating inner ellipticArcs
nframes:=73:  #73
for i from 0 to nframes do
a:=Rrado-(Rrado-Rradi)*(1-(nframes-i)/nframes):
framR[i]:=
ellipticArc([x0+w+l1,y0+h-Rrado],a,a,-Pi/2..Pi/2+.01,scaling=constrained, color=col):
end do:

#print(`plots[display](... here`);  
plots[display](stalkR,R1,upR, R2,r1,r2,seq(framR[i], i=0..nframes),opts);
plots[display](upR,R1,stalkR, R2,r1,r2,scaling=constrained, style=line,color=col);

 

display(convert(framR,list), insequence=true);

 

#Start to animate stalkR
#stalkR:=polygon([[x0+base-w,y0],[x0+w+l1, y0+h-2*Rrado],[x0+w+l1+w, y0+h-2*Rrado+w/4],[x0+base,y0]], color=col):
#AS:=Spline([[x0+base-w,y0],[x0+w+l1, y0+h-2*Rrado]],x):
x1:=eval(x0+w+l1):y1:=eval(y0+h-2*Rrado):
x2:=eval(x0+base-w):y2:=eval(y0):
AS:=CurveFitting:-LeastSquares([[x1,y1],[x2,y2]],x);
#print(`invalid argument 2/3+3/2*x which must be a plot structure, or a list/set/array thereof - in CS`);

#CS:=LeastSquares([[1,2],[2,4], [3,5]],x):
#print(`CS := INTERFACE_PLOT(AXESLABELS("",""),VIEW(-10. .. 10.,DEFAULT)) - for below`);
#CS:=plot(LeastSquares([[1,2],[2,4], [3,5]],x));
#print(`CS:=plot(curve([[1,2],[2,4], [3,5]],x)); - empty plot`);

#CS:=plot(curve([[1,2],[2,4], [3,5]],x));  #empty plot
 

AS := 10.4185185185185-2.39506172839506*x

(1)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Below works on printlevel:=6 -  but draws line segments only
CS:=curve([[1,2],[2,4], [3,5],[x1,y1],[x2,y2]]):
#print(`Plot of CS`);
plots[display](CS);
#   ...but gives no output on printlevel:=1
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 

 

#print(`Plot of points`);
lin1:=plot([[1,2],[2,4]]);
#plots[display](lin1);
 

 

#plot([[x1,y1], [x2,y2]]);  
#[x0+w+l1+w, y0+h-2*Rrado+w/4]], x):  #,[x0+base,y0]], x):
val1:=x0+w+l1;
#printf("x0=%5.3f  base=%5.3f  w=%5.3f  l1:=%5.3f val1=%5.3f   y0=%5.3f\n",x0,base,w,l1,val1,y0);
#val1:=x0+w+l1;
#print(`op(1,AS[ , ]`);
pl1:=plot(10-2*x, x=-1..5);
#plots[display](pl1);
AS;
op(1,AS);
op(1,AS[1]);
op(1,AS[1,1]);

val1 := 2.325000000

10.4185185185185-2.39506172839506*x

10.4185185185185

1

1

 

 


 

Download fixLettR.mws

The problem arises because assume() lasts for the 'duration' of the worksheet, until you hit a restart, or deliberately 'unassume' the variables. The first couple of execution groups place assumptions on 'x', 't', 'k', and then do so again. For reasons not completely clear to me, Maple doesn't seem to like making the same assumptions on the same variables twice. If you force an 'unassume', then the problem goes away. See the attached


 

#in separate cell
restart;

#in separate cell
interface(showassumed=0):
pde := diff(u(x, t), t)=k*diff(u(x, t), x$2);
ic:=u(x,0)=0: bc:=u(0,t)=t:
assume(x>0);assume(t>0);assume(k>0):
sol:= pdsolve({pde,ic,bc}, u(x,t));

#in separate cell. Now this gives error
#
# Not if you 'unassume' the variables, before
# 'assuming' them again
#
x:='x': t:='t': k:='k':
interface(showassumed=0):
pde := diff(u(x, t), t)=k*diff(u(x, t), x$2):
ic:=u(x,0)=0: bc:=u(0,t)=t:
assume(x>0);assume(t>0);assume(k>0):
sol:= pdsolve({pde,ic,bc}, u(x,t));
#error message now

#in one cell
restart;

#in one cell
interface(showassumed=0):
pde := diff(u(x, t), t)=k*diff(u(x, t), x$2):
ic:=u(x,0)=0: bc:=u(0,t)=t:
sol:= pdsolve({pde,ic,bc},u(x,t)) assuming x>0,t>0,k>0;

#in one cell, no error
interface(showassumed=0):
pde := diff(u(x, t), t)=k*diff(u(x, t), x$2):
ic:=u(x,0)=0: bc:=u(0,t)=t:
sol:= pdsolve({pde,ic,bc},u(x,t)) assuming x>0,t>0,k>0;

 

 

Download assumIssue.mw

This situation does not arise when using the 'assumiing' construct, because this only makes assumptions for the duration of a single command, and removes them when the associated command has completed

Your 2-D input is being interpreted in a way which you may not expect - see attached. If this isn't the interpretation you want, you will have to specify exactly what tou are trying to achieve


 

restart; (x-2)*(-1) = y+4 and y+4 = (z+5)*(1/2)

false

(1)

x := -3; y := 1; z := 5; (x-2)*(-1) = y+4 and y+4 = (z+5)*(1/2)

-3

 

1

 

5

 

true

(2)

#
# To verify this interpetation, copy-paste the
# expression here, where it will be converted
# to 1-D input, where the meaning becomes
# obvious
#
  (x-2)*(-1) = y+4 and y+4 = (z+5)*(1/2)


 

Download badExp.mw

restart;
seq
( assign( a[i], RootOf( _Z1^6-3*_Z1^2-2*_Z1+11,index = i)),
  i = 1 .. 6
);
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
evala(ee);

returns 4

  1. You say that " I want to examine them one at a time in MATLAB to know which one is right for me ". My immediate recommendation is to do the "examination" in Maple. After all, what do you plan to do in Matlab which cannot be done in Maple?!
  2. If you really, really want to transfer Maple's output to Matlab, then you should appreciate that trnsferring 'numeric' data is easy, but transferring 'symbolic' information can get tricky. Matlab really, really hates symbols. However, it is possible, but first I need to establish which symbolic toolbox you are using in Matlab? The default Matlab symbolic toolbox is based on MuPad, although it is possible to set up Maple as Matlab's symbolic toolbox. Which do you have?
  3. If you have Maple as the default symbolic toolbox in Matlab, then it *may* be easier to drive the Maple engine from within Matlab to get the answers you want, rather than drive the Maple engine separately, with subsequent transfer of results
  4. I would strongly suggest using (1) above

Your pde is first order in 't' and second order in  'x', so if you want a solution which does not rely on on arbitrary constants you will require three boundary/initial conditions. You only have two.

If you can come up with a third boundary condition, then I would suggest attempting a numeric solution for this problem (with "infinity" defined as 10, 100, 1000 whatever, just to check what difference it makes)

If I "clean up" your worksheet - not changing anything, just getting rid of pointless crap,and adding a few simplify() wrappers, I end up with the attached (saved with output).

It works in all Maple releases back to Maple 18. I can't try Maple 12, because I simply do not have anything that old.

Now, in terms of this worksheet - please clearly explain - what exactly is your problem?

badws.mw

not sure what range of values is implied by the requirement |delta|<<1, but the following will plot z(x) versus x over the range x=-Pi/4..Pi/4, for delta-values from -0.5 to 0.5 in steps of 0.1

restart;
with(plots):
ode:=(diff(z(x), x, x))-z(x) - cos(2*x)/(1+delta*z(x)) = 0;
conds:= z(-Pi/4)=0,
        z(Pi/4)=0;
display
( [ seq
    ( odeplot
      ( dsolve
        ( [ eval(ode, delta=k),
            conds
          ],
          numeric
        ),
        [x, z(x)],
        x = -Pi/4..Pi/4
      ),
      k=-0.5..0.5, 0.1
    )
  ]
);

diff(diff(z(x), x), x)-z(x)-cos(2*x)/(1+delta*z(x)) = 0

 

z(-(1/4)*Pi) = 0, z((1/4)*Pi) = 0

 

 

 

 

 

Download odeplot.mw

in Maple 2015.2. Check the attached.


docPlot.mw

 

Yoor function has four local maxima in the range 0<=x<=1. As the help page for for Optimization:-Maximize() makes clear (my emphasis)

The Minimize command computes a local minimum of an objective function, possibly subject to constraints.  If the problem is convex (for example, when the objective function and constraints are linear), the solution will also be a global minimum.  The Maximize command is similar to the Minimize command except that it computes a local maximum.

So the best you can guarantee with this command (since your function is not convex) is to get a local maximum.

Global optimization is a much harder problem than local optimization. Indeed AFAIK, for non-convex problems, there is no way to absolutely guarantee that a global optimum will be found. Obviously some "so-called global" optimizers will do better than others.

Out of idle curiosity I tried your problem with the DirectSearch() package: a third-party (free) Maple add-on available from the Maple Application which does claim to be a "global" optimizer

DirectSearch:-Search( 100*(abs(app(x)-ex(x))),[x>=0, x<=1], maximize=true);

returns [.183847185739183, [x = .923034185006713], 19], which actually is the "global" maximum for 0<=x<=1.

So you have a couple of choices

  1. Restrict the range of 'x' to 0.8..1.0, and use Maple's default optimiser
  2. Download/install the DirectSearch() package from the Maple Applications Centre; this obviously works better than the in-built default routines for some probelms
First 140 141 142 143 144 145 146 Last Page 142 of 207