tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are answers submitted by tomleslie

what is shown in the attached

restart;
data := Vector[column](25, [0, 0, 0, 0, 0., 0, -.12901351888865177210172017415364583333333333333333, -0.99242368143093037923177083333333333333333333333340e-1, .37625367305666259757677714029947916666666666666666, .56250000000000000000000000000000000000000000000000, 0, -.19475144716868229166666666666666666666666666666667, -.21163024381866666666666666666666666666666666666666, .12728253980166145833333333333333333333333333333334, 1.0000000000000000000000000000000000000000000000000, 0, -0.88292457198317913770675659179687500000000000000009e-1, -.14358380077549029541015624999999999999999999999989, -.26169225877306929516792297363281249999999999999994, .56250000000000000000000000000000000000000000000000, 0, 0, 0, 0, 0.]):
#
# Plot the above data as a function of the index value
#
  xv:=Vector[column](op(1, data), [seq(j, j=1..op(1, data))]):
  plot( xv, data, style=line);

 

#
# Export the data to a file. NB OP will have to change
# the path/filename to something appropriate for his/her
# machine
#
  ExportMatrix("C:/Users/TomLeslie/Desktop/testdata.csv", convert(data, Matrix));

665

(1)

 


 

Download dataplot.mw

Under normal (ie non-educational) circumstances, the exact solution for the ODE (system) would not be known.

It is however still possible to use the numerical solution of the BVP to compute initial conditions, and solve this revised ODE (system) as an IVP.

The general process is as follows

  1. Solve the BVP subject to the boundary conditions, say u(0)=a, u(1)=b
  2. Note that, from this BVP solution, one can obtain the value of D(u)(0). Since one now "knows" u(0) and D(u)(0), the original boundary conditions have been transformed into initial conditions, and the original BVP can now be solved as an IVP.

This process is illustrated in the attached for the first question in your supplied. Subsequent questions can be solved with the same approach - these are left as an exercise for the OP!

  restart;

#
# Set up the ODE + BCs and compute the
# exact solution. Note that although
# the boundary conditions are given at
# u(0)=0, u(1)=0, the solution can be
# plotted over any range of the
# independent variable
#
  eq:= diff(u(x),x,x)+1/9*u(x)=x^2+exp(x):
  ics:= u(0)=0, u(1)=0:
  exactSol:= dsolve( [eq, ics]):
  pExact1:= plot( rhs(exactSol),
                  x=0..1
                );
  pExact2:= plot( rhs(exactSol),
                  x=0..2
                );

 

 

#
# Now solve the example numerically as a BVP.
# Note that this solution *cannot* be plotted
# outside the range given by the BCs
#
  BVPsol:= dsolve( [eq,ics],
                  numeric
                ):
  pBVP1:= plots:-odeplot( BVPsol,
                          [x, u(x)],
                          x=0..1
                        );
  pBVP2:= plots:-odeplot( BVPsol,
                          [x, u(x)],
                          x=0..2
                        );
#
# As some kind of check, Plot the error between
# the BVP solution and the exact solution over the
# range x=0..1. Under "normal" circumstances, one
# wouldn't "know" the exact solution
#
  pBVP3:= plots:-odeplot( BVPsol,
                          [x, u(x)-rhs(exactSol)],
                          x=0..1
                        );

 

Warning, right boundary of range exceeds domain of the problem, it has been adjusted

 

 

 

#
# Now set up the "shooting" method, using only
# the numerical solution of the BVP, given above
#
# Instead of using the boundary condition u(1)=0,
# directly, obtain the value for D(u)(0) which
# will result in u(1)=0.
#
# Thus solve what is now an IVP
#
  IVPsol:= dsolve
           ( [ eq,
               u(0)=0,
               D(u)(0)= eval
                        ( diff(u(x),x),
                          dsolve
                          ( [ eq, ics ],
                            numeric,
                            output=listprocedure
                          )
                        )(0)
             ],
             numeric
           ):
#
# Note that since we now have an IVP solution, it can
# be plotted for any range of the independent variable
#
  pIVP1:= plots:-odeplot( IVPsol,
                          [x, u(x)],
                          x=0..1
                        );
  pIVP2:= plots:-odeplot( IVPsol,
                          [x, u(x)],
                          x=0..2
                        );
#
# Plot the error between the IVP solution and the
# exact solution over the ranges x=0..1, and x=0..2
#
  pBVP3:= plots:-odeplot( IVPsol,
                          [x, u(x)-rhs(exactSol)],
                          x=0..1
                        );
  pBVP4:= plots:-odeplot( IVPsol,
                          [x, u(x)-rhs(exactSol)],
                          x=0..2
                        );
  

 

 

 

 

 

 

Download shoot.mw

 

The worksheet you supply does not provide the indicated output in Maple 2018.1 - but it does in Maple 18!

Diagnosing the "difference" between the two Maple versions would probably take (me) longer than fixing what I guess is your basic problem, which is basically a "last name evaluation" issue. The attached shows your original code (with output) and my revision (with output). Note that the final entry  -1.861224927*10^(-12) in my revised code, is the value which your original code displays for all entries. You need to "force" the evaluation for P[  ], on each iteration of the loop- otherwise P[ ] will always use the value of mu on loop completion for all entries - whihc I'm guessing you don't want

``

``

restart

with(LinearAlgebra)

MCK := Matrix(1, 1, {(1, 1) = 0.1627682387e-16*mu})

P := Matrix(2, 111)

`ρ__∞` := 1.225

j := 1

for `U__&infin;` from 333 to 335 do `M__&infin;` := `U__&infin;`/(331.2); mu := `&rho;__&infin;`*`U__&infin;`*(`M__&infin;`^2-2)/sqrt((`M__&infin;`^2-1)^3); P[1 .. 2, j] := `<,>`(`<,>`(MCK), `<,>`(j)); j := j+1 end do

P[1, 1 .. j-1]

Vector[row](3, {(1) = -0.1861224927e-11, (2) = -0.1861224927e-11, (3) = -0.1861224927e-11})

(1)

restart

with(LinearAlgebra):

MCK := Matrix(1, 1, {(1, 1) = 0.1627682387e-16*mu})

P := Matrix(2, 111):

`&rho;__&infin;` := 1.225:

j := 1:

for `U__&infin;` from 333 to 335 do `M__&infin;` := `U__&infin;`/(331.2); mu := `&rho;__&infin;`*`U__&infin;`*(`M__&infin;`^2-2)/sqrt((`M__&infin;`^2-1)^3); P[1 .. 2, j] := `~`[eval](`<,>`(`<,>`(MCK), `<,>`(j))); j := j+1 end do:

P[1, 1 .. j-1]

Vector[row](3, {(1) = -0.5771710868e-11, (2) = -0.2958832005e-11, (3) = -0.1861224927e-11})

(2)

``

NULL


 

Download SooalFix.mw

You can change the size of the plot window by using the size=[w,h] option in the plot command.

There are a variety of ways you can define this 'window size' (see the help at ?plot/options.

The most common way is probably(?) to supply a couple of integers (>10) which define the size in terms of screen pixels. Obviously the 'size' you end up with depends on the resolution of your monitor

Second most common way is probably to use a couple of numbers (<1) which determine the  plot window size as a multiple of whatever worksheet width you happen to be using - so [0.9 , 0.9] will give a width which (very nearly) fills the width of the worksheet (and is "square")

Note that if you use numbers 1<w<10, then the second of the above interpretations will be applied, and the plot will be "larger" than your worksheet widrh (and you will have to use the scroll bars to move around it). I never find this choice very useful

Both display() and textplot() are commands within the plots() package. So in order to access these commands, you can either use

with(plots);

to load all the commands in the package, or

plots:-textplot()

plots:-display()

to access the commands individually.

You already have the command with(plots, implicitplot, implicitplot3d) - but this only makes the commands implicitplot() and implicitplot3d() available

In the attached, I have added a with(plots) command to your worksheet, and everything now works

 

af_eq := (3*alpha[2](t[1], t[2])*A^3*(1/8)-A*sigma)^2+(1/4)*alpha[1](t[1], t[2])^2*A^2 = (1/4)*f0^2

(.9701625000*A^3-A*sigma)^2+0.1892250000e-4*A^2 = 0.2500000000e-2

(1)

 alpha[1]:=0.0087;alpha[2]:=2.5871;f0:=f[0]

0.87e-2

 

2.5871

 

f[0]

(2)

 

with(plots, implicitplot,implicitplot3d):

 f0 :=0.1; alpha[1]:=0.0087;alpha[2]:=2.5871;

.1

 

0.87e-2

 

2.5871

(3)

p1:=implicitplot(af_eq, sigma = -1.2 .. 2, A = 0 .. 2,  numpoints = 20000, axes = box, axesfont=[SYMBOL, 14],labels = [sigma, A], labelfont = [SYMBOL, 16],color="Red",tickmarks=[9,12],thickness=2);

 

with(plots):

t11 := textplot([-.5, 1, ('typeset')("Peak ")])

t22 := textplot([-.5, 1.2, ('typeset')("Lower ")])

display({p1, t11, t22}, 'view' = [-1.2 .. 2, 0 .. 2])

 

 


 

Download withplots.mw

I can't run this code - lots of "Errors". It is possible that this is a version issue! Which Maple version was used to create it?

Just by reading your code, there are a couple of issues which make me nervous, and which you might want to consider.

  1. You define a "white" square which covers the whole plot region. Maple has a "stacking order" for plots - anything below this "white" square in the stack will not be visible, anything above this "white square will be visible. Unless you really need this "white" square, remove it!
  2. Since your display() commands uses a 'set' rather than a 'list' as a container for the plots, you cannot even predict/control the order of plots in the "stack",Together with the "white" square mentioned above, this might lead to weird results. Change the display( {} ) to display( [] ) - ie 'list' not 'set'. The order of plots in the list fixes the stacking order. You can then experiment by changing the order of plots in the list. I'm pretty sure that the "first" plot in the list is the "bottom" of the stack, which is where I'd put the "white" square, so that it does not obscure anything.

First of all this operation is OS-dependent: the following discussion refers to a 64-bit Windows installation. With any other OS, some adjustment will  be necessary

  1. I'm assuming that you had Maple 2017 running with Matlab 2017 - correct? Because if you had this running then it will continue to run - unless
  2. When you installed Maple 2018, you overwrote/deleted your Maple 2017 installation: ie Matlab 2017 wants to communicate with Maple 2017, but Maple 2017 does not exist any more
  3. To re-establish the link you need to run the file MapleToolbox2018.0WindowsX64Installer.exe which can be found in C:\Program Files\Maple 2018
  4. You should be aware that whenever you update either Maple or Matlab, then this link has to be re-established by running the afore-mentioned executable

If you aren't going to do anything "too clever" with the vertical lines, then your best bet is probably to use the axis[1] option, with the gridlines=[] suboption.

If you want to specify properties of individual vertical lines, then you can do almost anything with plottools:-line()

Check out the examples in the attached. (As always, plots render rather better within Maple than they do on this website)

restart;
p1:= plot( t^2*sin(t),
           t=-2*Pi..2*Pi,
           axis[1]=[ gridlines=[ [-Pi, -Pi/2, Pi/2, Pi]
                               ]
                   ],
           axes=boxed
         );

 

p1:= plot( t^2*sin(t),
           t=-2*Pi..2*Pi
         ):
yr:=[op([2,2,1..2], plottools:-getdata(p1))]:
lvals:= plottools:-line( [-Pi,   yr[1]], [-Pi,   yr[2]], color=red, thickness=3),
        plottools:-line( [-Pi/2, yr[1]], [-Pi/2, yr[2]], color=blue, linestyle=dash),
        plottools:-line( [ Pi,   yr[1]], [ Pi,   yr[2]], color=green, thickness=5, linestyle=dot):
plots:-display([p1, lvals], axes=boxed);

 

 

Download vLine.mw

 

when only part of the problem is given - since I have no idea what g(x,t) might be!

However if I just pick an example from the pdsolve/numeric help page, then the attached will work.

If you still have issues then you will have to post more detials of your specific problem

  restart;
#
# Setup/solve the 'toy' example
#
  PDE := diff(u(x,t),t)=-diff(u(x,t),x);
  IBC := {u(x,0)=sin(2*Pi*x),u(0,t)=-sin(2*Pi*t)};
  pds := pdsolve(PDE,IBC,numeric,time=t,range=0..1);
#
# define the desired integral. NB range is
# arbitrary, but it probably ought to be
# "within" the range defined within the
# pdsolve() command
#
  f:= tau->Int
           ( rhs
             ( pds:-value
                    ( t=tau,
                      output=listprocedure
                    )[3]
             )(x),
             x=0.25..0.75
           ):
#
# Compute the integral for a few different 'time' values
#
  evalf(f(0.1));
  evalf(f(0.2));
  evalf(f(0.5));

diff(u(x, t), t) = -(diff(u(x, t), x))

 

{u(0, t) = -sin(2*Pi*t), u(x, 0) = sin(2*Pi*x)}

 

_m714588928

 

HFloat(0.18707013161493055)

 

HFloat(0.30268583123287324)

 

HFloat(-1.2958901818599123e-16)

(1)

 

Download pdeInt.mw

provides solutions for *some* of the curves you want. You really should put in a little effort on your own homework.

Extending ths to cover *all* of the curves sholud not be too difficult. I know, because I've done it (just not here)

fns:=[sin(x), 1/(x-1), exp(x)]:
tfns:=convert(map( taylor, fns, x=0, 8), polynom):
for j from 1 by 1 to numelems(fns) do
    plot( [ fns[j], tfns[j]],
            x=-8..8,
            view=[-8..8, -5..5],
            discont=true,
            scaling=constrained,
            title=typeset( "function=",fns[j]),
            titlefont=[times, bold, 20],
            tickmarks=[decimalticks, decimalticks],
            color=[red, blue],
            legend=[exact, taylor],
            legendstyle=[location=right]
         ):
od;

 

 

 

 

Download basicPlots.mw

 

Such reading took me about 10secs.

How long have you been waiting for an answer because you are incapable of reading the help?

Form the help at ?combine/ln, which is a pretty fair description of what you want to do

restart;
combine( ln(x) + ln(y), ln, symbolic);

works

that x is a "number", real or complex and you want to make the assignment x:=b, whenever x has a non-zero imaginary part, then you could use

if not type(x, realcons)
then x:=b:
fi;

i.e has a non-zero imaginary part, for t> a certain value. There are two possibilities

  1. complex solutions are expected/possible for your PDE system, in which case it will be necessary to 'split' the PDE system into two, representing real and imaginary parts. This is possible to do
  2. complex solutions should not occur - in which case you (probably?) have a typo somewhere - could be very tricky to find!

Only you know whihc of the above is more likely

The 'alias()' solution which I suggested for your earlier (similar?) issue at

https://www.mapleprimes.com/questions/225232-Replacing-Suffixed-Using-Subsindents

works in this case as well, so

restart;
alias( n=_Z,
          seq( cat(n,j)=cat(_Z, j), j=1..100),
         C=_C,
         seq( cat(C,j)=cat(_C, j), j=1..100),
         c=_c,
         seq( cat(c,j)=cat(_c, j), j=1..100)
       ):
ode:=2*sqrt(x)*diff(y(x),x)=sqrt(1-y(x)^2):
maple_sol:=dsolve(ode,y(x)):
odetest( maple_sol, ode);

will return '0' from odetest()

I still do not recommend this solution, and advise against usage, to fix a problem which is merely "cosmetic"

As the Maple help states (my emphasis)

  • Any symbol beginning with an underscore (_) is effectively reserved for use only by library code. It is not available to users. Failure to observe this rule can lead to unexpected results.
  • This restriction is not imposed by the Maple language, but rather by library convention. Therefore, it is a system-level restriction that is not enforced.

The important thing to realise about this is the (rather obvious) corollary of the frist bullest above - namely that any symbol whihc does not start with an underscore (_) is not reserved for use by library code. In other words, if it starts with an underscore, it is "special" and if it doesn't start with an underscore, then it "isn't special"

Now how happy do you feel about replacing names which are treated as special with names which are not treated as special?

You state that you have "learned" to use

subsindets(expr, 'suffixed(_)', f->n);

well unlearn it - very quickly! Consider the "toy" example

restart;
expr:=f(_Z, _Z1, _Z2, _C, _C1, _C2, _c, _c1);
subsindets(expr, 'suffixed(_)', f->n);

which, of course returns f(n, n, n, n, n, n, n, n), - and I'll bet cash money that this is not what you want/desire!

Now I can't get too excited about "cosmetic" issues like variable names, but if I absolutely had to come up with a workaround, then I would probably use alias() Theoretically anything set up using the alias() command is "translated" by the parser, before dispatch to any underling code, and anything returned by underlying code is "translated" back again before display - so this might work.

It is relatively trivial to set up enough "aliases" to handle any situation you are likely to come across - you only have to deal with _Zn, _Cn and _cn. There might be others which I haven't come across, or possibly forgotten about, but changing the above "toy" example to

restart;
alias( n=_Z,
          seq( cat(n,j)=cat(_Z, j), j=1..100),
          C=_C,
          seq( cat(C,j)=cat(_C, j), j=1..100),
          c=_c,
          seq( cat(c,j)=cat(_c, j), j=1..100)
       ):
expr:=f(_Z, _Z1, _Z2, _C, _C1, _C2, _c, _c1);

will return expr := f(n, n1, n2, C, C1, C2, c, c1), which is at least close to what you (probably) intended.

Of course you will have to be careful not to use the names C, C1, C2..C100, Z, Z1, Z2..Z100, c, c1, c2..c100 anywhere else in your worksheet - or all hell could break out.

Would I recommend this workaround as a "solution" to a problem which is purely cosmetic? - NO!

 

First 127 128 129 130 131 132 133 Last Page 129 of 207