acer

32385 Reputation

29 Badges

19 years, 335 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity) assuming x::real;

                                     (1/2)   
                                   Pi        
                                -------------
                                            2
                                2 (exp(|x|)) 

 

If the table tells you that the expected answer depends on a special condition or restriction then you could try using that as an assumption.

Also, without the restriction but with a particular method forced,

restart;

simplify(int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity, method=meijerg));

                    1        2   (1/2)                  
                    - csgn(x)  Pi      exp(-2 csgn(x) x)
                    2       

See also the results from various methods of definite integration,

simplify(int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity, method=_RETURNVERBOSE));

acer

When you call just `int` with exact end-points it attempts to do symbolic integration, which was hitting an uncaught error internally. You can force numerical quadrature by either 1) supplying float end-points, 2) supplying the `numeric` option to `int`, or 3) calling it as `evalf(Int(...))`.

V1:=<seq(x, x=0..1, 0.1)>:

V2:=<seq(x^2, x=0..1, 0.1)>:

y:=x->CurveFitting:-ArrayInterpolation(V1,V2,x,method=spline):

int(y, 0..1.0);                                               
                               0.333429558010905

int(y, 0..1, numeric);
                               0.333429558010905

evalf(Int(y, 0..1));
                               0.333429558010905

y:=x->CurveFitting:-ArrayInterpolation(V1,V2,x,method=spline,degree=5):

int(y, 0..1, numeric);
                               0.333333333333311

For efficiency with a large amount of data you should import your Vector and give them datatype=float[8].

For very large amounts of data the construction and evaluation of the piecewise returned by CurveFitting:-Spline (or its symbolic integral) can become quite expensive. (This may have become less of an issue, if Maple can sort the "univariate" piecewise conditions so that evaluating it at a point can do a quicker binary search. It's more expensive if it has/had to check conditonals from left to right.)

acer

Yes. One way is to save it to a .mla "library archive", using LibraryTools.

Then you can access it in any new session that has that library file's location in libname. And if you want that part to be automatic (for all new sessions) then you can set libname in your initialization file.

acer

Change those square brackets to round brackets.

In Maple the square brackets construct a list. You have a list raised to the power 2. I suppose you intended to obtain a scalar quantity, to be plotted.

In Maple round brackets are used as delimiters.

acer

Put a multiplication sign between the x and the (12*t+1) , if that's what you intended.

Or did you intend for that to a be function application?

acer

The Intel i5 and i7 series CPUs do well, even for the releases of a few years ago. That is you dont need the latest and greatest, which are not cost ineffective anyway. I don't suggest a Xeon for the same reason. I don't suggest a Xeon phi as it requires a special build against a special version of the Intel MKL (which maple doesn't offer) to attain its peak numeric linear algebra capabilities.

I recommend an nvidia graphics card over an ATI card. Not latest and greatest, both to hit cost effectiveness and minimize chances of driver problems. Some older ATI  cards caused problems with hardware acceleration of plots and manual 3D plot rotation.

The choice of Operating System matters. I recommend 64bit Maple for performance. Overall I perceive best performance on 64bit Linux.

acer

Replace (e)^(x) with exp(x) .

Also, define your operator like,

f := x -> -ln(x)+exp(x)

But don't put f(x) on the left-hand-side of an assignment statement. It's an abomination.

acer

How about just using the older mechanism, for which ~ is a newer short syntax?

map(int8,map(round,S))

acer

You problem seems to be that you were expecting subs to do an evaluation, following syntactic substitution. It doesn't. Use eval instead. This is a frequently asked question.

restart;

f := diff(y(x),x,x) + y(x) = sin(x):

subs(y(x) = sin(x), f);

                       /  2        \                  
                       | d         |                  
                       |---- sin(x)| + sin(x) = sin(x)
                       |   2       |                  
                       \ dx        /                  

%; # an evalution

                                 0 = sin(x)

eval(f, y(x) = sin(x));

                                 0 = sin(x)

acer

Why not make Track a submodule of Lattice? If you give submodule Track its own ModuleApply then you can continue to call it as before. But it could then have trackElement as its own module local.

Btw the example you posted would work if you hade trackElement defined prior to using it, inside the body of Track. One reason that's undesirable is that Maple has to recreate trackElement each time Track is called, which is a waste of resources.

acer

It isn't clear to whether you are asking for a way merely to display the list r and the list of its type-checked results in an aligned and tabulated manner.

Other have shown how to print a sequence of lists of lists, which displays horizontally across the worksheet.

But it occurs to me that you might instead be asking for ways to print the pairwise, vertically stacked, and horizontally aligned, results. That is, with a row of entries of r displayed on top of a row of the type-check results. It occurs to me that you may be looking for such a particular form of display, for the sake of your students, say.

So, on the chance that I've guessed rightly, here are a few ways to get that effect without the need to clutter the worksheet with the fenced boundaries of a pretty-printed Matrix. Note that in the examples below there is no returned value from the code which does the display. It's just an act akin to printing.

If current and older Maple you can use the printf command for such formatted display. A drawback here is that there is not prettyprinting of 2D Math.

In Maple 2015.1, using the Standard Java GUI you can also get a variety of effects from an embedded GUI Table, using the DocumentTools:-Tabulate command. Again, please note that neither of these commands return a value, and moreover you can't interleave all of this display amongst other regularly printed output in the same Execution Group.


restart;

r := [-3, -2.5, 0, 1, 3/2, Pi, sqrt(5)]:

printf("%{}9a\n\n%{}9a\n\n", <r>, <type~(r,nonnegint)>);

       -3      -2.5         0         1       3/2        Pi   5^(1/2)


    false     false      true      true     false     false     false

L := [r, type~(r,nonnegint)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(L, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

 
  By using strings for true and false we can get them shown with an upright font.

LL := [r, convert~(type~(r,nonnegint),string)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

LLL := [["",r[]],
     ["nonnegint",convert~(type~(r,nonnegint),string)[]],
     ["numeric",convert~(type~(r,numeric),string)[]],
     ["realcons",convert~(type~(r,realcons),string)[]]]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LLL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none,
                        color=((T,i,j)->`if`(j=1,black,
                               `if`(T[i,j]="true","#009900","#bb0000"))),
                        fillcolor=((T,i,j)->`if`(i=1 or j=1, "#dddddd", "#cccccc")));
interface(typesetting=oldsetting):

 

-3

-2.5

0

1

3/2

Pi

sqrt(5)

nonnegint

false

false

true

true

false

false

false

numeric

true

true

true

true

true

false

false

realcons

true

true

true

true

true

true

true

 

 


tabled.mw

acer

@yellowcanary Be more careful with your implicit multiplication when using 2D Math.

The expression assigned to `Profit`, and the (unassigned) third expression on your original Worksheet are both missing a space (or explicit multiplication symbol) in the first occurence of the subexpression Pa(1-Pb) . What you have there is a function application rather than a product of terms. When Pa gets any numeric value (eg. while plotting) this subexpression evaluates to just that value.

Tom Leslie inadvertantly copied and used this mistaken variant of the `Profit1` expression, I believe.

So correct this by adding in the missing space or an explicit multiplication symbol for this example. Or be safer and always use explicit multiplication, or learn to be safer still and use 1D Maple Notation input mode so that attempts at implicit multiplication gets flagged as a syntax error.

When `Profit1` is corrected, the two surfaces appear more different than before. This helps makes the plotted situation clearer.

You can also use lighting, tranparency, and orientation to try and make the whole thing more clear (given a single static viewpoint). It looks not so bad if plotted like this,

p1:=plot3d(Profit1, Pa=0..Pb, Pb=0..1, color=red, transparency=0.0):
  p2:=plot3d(Profit3, Pa=0..Pb, Pb=0..1, color="Blue", transparency=0.3):
  plots:-display(p1,p2, style=patchnogrid, glossiness=1.0,
                 lightmodel=Light3, orientation=[-150,75,0]);

Another possibility is to add a plot the difference, Profit1-Profit3 . You could even display that beside the original, (or separately, your choice) using something like,

with(plots):
p3:=plot3d(Profit1-Profit3, Pa=0..Pb, Pb=0..1, color=green):
display(Array([ display(p1,p2), p3 ]),
        style=patchnogrid, glossiness=1.0,
        lightmodel=Light3, orientation=[-150,75,0]);

There are several of ways to go.

Using 2D Math input mode, start typing out the equation. At the point where you've just typed the keys d i f f stop and use the simultaneous keystroke combination Ctrl-Tab-spacebar .

On MS-Windows that invokes command-completion on diff. It shows a popup menu of choices. It looks to me as if you want the 3rd entry down, for d/dt. Replace the purple placeholder in the inserted d/dt. For the second derivative raise the top "d" in the d/dt to the power of 2, to get d^2/dt, now all in blackMove the cursor left and continue typing x(t), etc. Use the same process for the other derivative.

This gives you a keyboard acceleration, to get prettyprinted 2D Input. The alternative is to use the palettes (which entails moving your hand off and on the keyboard and mouse pointer, repeatedly.)

Once you've entered you 2D Math ODE you can solve it by typing out a call to the command dsolve. But alternatively you can right-click on the 2D Math expression and use the so-called context-sensitive menu items. The item to choose in the right-click popup is "Solve DE", which offers the subchoice "x(t)".

You can use the right-click context-menus on the 2D Output or the 2D Input (if you have it, as you would here).

On other Operating Systems the keyboard accelerations can be a bit different. See here.

acer

Change that last line of SteamTables.mws to the following (with the file name changed appropriately, for your own computer).

save C00z, bz, A0z, EntropySaturatedLiquidWater, TriplePointPressureWater, bbz, lz,
 SubregionEntropy6z, Bz, CriticalTemperatureWater, SpecificVolumeSaturatedVaporWater,
 alphaz, zz, TriplePointTemperatureWater, C0z, SubregionVolume3z, wz,
 SubregionEntropy5z, SpecificVolumeWater, Lz, SubregionVolume2z, SubregionEnthalpy6z,
 SubregionEnthalpy4z, B00z, SaturationPressureWater, SubregionEnthalpy1z,
 SubregionEnthalpy2z, beta_LLz, alpha0z, beta_Lz, kz, Vz, betaz, Tz, beta_kz, Az, Cz,
 EnthalpySaturatedVaporWater, EntropyWater, SubregionVolume4z,
 SaturationTemperatureWater, EnthalpyWater, CriticalPressureWater, SatTempSubz,
 SpecificVolumeSaturatedLiquidWater, SubregionEntropy2z, nz, Xz,
 EnthalpySaturatedLiquidWater, thetaz, CriticalSpecificVolumeWater,
 SubregionVolume5z, SubregionEnthalpy3z, B0z, Pz, SubregionVolume6z,
 SubregionVolume1z, EntropySaturatedVaporWater, az, dz, SubregionEntropy1z,
 SubregionEntropy3z, SubregionEnthalpy5z, SubregionEntropy4z, "C:\\TEMP\\SteamTables.m";

After that I was able to do the example from Working-w-SteamTables.mws , in a new worksheet,

read "C:\\TEMP\\SteamTables.m";

SpecificVolumeWater(.2*MPa,500*K);

                                      3
                         1.144220489 m 
                         --------------
                               kg      

 

(In passing, this post might be of some interest.)

acer

You can operate beforehand with the more modern Vector V, and then convert that to (deprecated, lowercase) vector VV just for the codegen operations.

This can alleviate (and centralize) the inconvenience, if your V is the result of some earlier computations involving commands which return the more modern Vector.

restart;

with(codegen, optimize, makeproc);

                            [optimize, makeproc]

V := Vector(4);

                                       [0]
                                       [ ]
                                       [0]
                                  V := [ ]
                                       [0]
                                       [ ]
                                       [0]

V[1] := x+y; 
                                V[1] := x + y

V[2] := x^2+y^2;

                                        2    2
                               V[2] := x  + y 

V[3] := x^3+y^3; 

                                        3    3
                               V[3] := x  + y 

V[4] := x^2+y^2+x+y;

                                    2    2        
                           V[4] := x  + y  + x + y

VV:=convert(V,vector);

                    [        2    2   3    3   2    2        ]
              VV := [x + y, x  + y , x  + y , x  + y  + x + y]

T := makeproc([optimize(VV, 'tryhard')], [x, y]);

                           T := proc(x, y)
                           local t1, t2, t5, t6;
                             t6 := x + y;
                             t1 := y^2;
                             t2 := x^2;
                             t5 := t1 + t2;
                             VV[1] := t6;
                             VV[2] := t5;
                             VV[3] := t1*y + t2*x;
                             VV[4] := t5 + t6;
                           end proc;

acer

First 219 220 221 222 223 224 225 Last Page 221 of 336