acer

32405 Reputation

29 Badges

19 years, 351 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You can use the ExcelTools:-Export command.

If you export a list to .xls file then the entries should appear as a row within your spreadsheet application (eg. Excel).

If you export a column Vector to .xls file then the entries should appear as a column within your spreadsheet application. When you call the Vector command in Maple the default for it to act like the Vector[column] command and to produce a column Vector.

For example,

L := [seq(fsolve(x*y=1),x=1..2,0.2)];

V := Vector(L);

ExcelTools:-Export(L, "f1.xls");

ExcelTools:-Export(V, "f2.xls");

You will find that even the basics commands of the Maple programming language allow for much more power and flexibility than the right-click or context-menu actions ever can. It's worthwhile figuring out how to do such things purely programmatically.

Here are two (related) ways to obtain your other solutions, that involve first isolating or eliminating the y from F.

(I broke it into two steps, to try and make it more clear.)

restart;
F,G := x*y^2-x,x*sin(Pi*y):

W := solve(F,{y});

                W := {y = 1}, {y = -1}

seq(u union solve(eval({F,G},u),{x}), u=W);

             {x = x, y = 1}, {x = x, y = -1}
restart;                                                                           
F,G := x*y^2-x,x*sin(Pi*y):                                                        

T := eliminate({F,G}, {y});

           T := [{y = -1}, {}], [{y = 1}, {}]

seq(u[1] union solve(eval({F,G},u[1]),{x}), u=T);

             {x = x, y = -1}, {x = x, y = 1}

You can use 2-argument eval to get at the values.

You can use an assignment statement (ie,:= the colon-equals) or the assign command.

For example,

sol := solve({x+y=3,x-y=-2});

          sol := {x = 1/2, y = 5/2}

eval(x, sol);

                     1/2

eval(y, sol);

                     5/2

assign('A', eval(x, sol));

A;

                     1/2

A := eval(x, sol);

                   A := 1/2

B := eval(y, sol);

                   B := 5/2

If you use the rhs command, or index into the solution by position, then you're doing it wrongly.

You have mixed up the allowed format for the data passed as a the first argument to the LeastSquaresPlot command.

You could pass a list of lists for the points, as is documented in the Help page for that command. But you passed a 10-element Array where each entry is a list of two values, which is not accepted by the command.

Try these:

   LL := convert(points, list);
   LeastSquaresPlot(LL, x, curve = c*x, boxoptions = [color = magenta],
                                 view = [default, (min .. max)(LL[.., 2])]);

   LeastSquaresPlot(LL, x, curve = c*x, boxoptions = [color = magenta]);

It's not clear to me what you are trying to accomplish, since there is only one free variable in the example you gave.

Could you explain what you want to be the second independent variable? I am going to guess that you mean the upper value of the index of summation.

restart;

plot(add(BesselJ(n,r),n=0..5),r=-10..10);

plots:-contourplot(sum(BesselJ(n,r),n=0..i),
                   r=-10..10,i=1..5,grid=[201,5],
                   contourlabels=false,
                   filled, coloring=["Navy", "Orange"]);

 

 

Download contourplot_sum.mw

Or possibly this (though not so interesting...)

plots:-contourplot(sum(BesselJ(n,r),n=0..floor(i)),
                   r=-10..10,i=0..5,grid=[51,201],
                   contourlabels=false,
                   filled, coloring=["Navy", "Orange"]);

My oracle came up with these.

You'll have to judge whether the author's of these textbook examples might consider the solutions to be real, or what you think of squaring (or apply exp to)  both sides of an intermediate equation, etc.

restart;

#903
ode:=diff(y(x),x)-y(x) = x*y(x)^(1/2):
ic:=y(0)=4:
sol:=dsolve([ode,ic],y(x)):
H:=odetest(sol,ode):
simplify((rhs-lhs)(map(`^`,isolate(H,indets(H,radical)[1]),2)));
simplify(factor(subs(exp(x)=exp(x/2)^2,H))) assuming real;

0

0

restart;
#1966
#Book: Differential equations for engineers by Wei-Chau XIE, Cambridge Press 2010
#Section: Chapter 2
#Problem number: 92.
restart;
ode:=2*x*diff(y(x),x)-y(x) = ln(diff(y(x),x)):
sol:=dsolve(ode,y(x)):
H1:=odetest(sol[1],ode):
H2:=odetest(sol[2],ode):
simplify((rhs-lhs)(rationalize(map(exp,isolate(combine(H1),op(2,H1))))));
simplify((rhs-lhs)(rationalize(map(exp,isolate(combine(H2),op(2,H2))))));

0

0

restart;
#3035
#Book: Ordinary differential equations and their solutions. By George Moseley Murphy. 1960
#Section: Various 37
#Problem number: 1118.
restart;
ode:=(diff(y(x),x)^2+1)^(1/2)+a*diff(y(x),x) = x:
sol:=[dsolve(ode,y(x))]:
H1:=odetest(sol[1],ode):
H2:=odetest(sol[2],ode):
simplify((rhs-lhs)(map(`^`,isolate(H1,indets(H1,radical)[1]),2)));
simplify((rhs-lhs)(map(`^`,isolate(H2,indets(H2,radical)[1]),2)));

0

0

restart;
#3036
#Book: Ordinary differential equations and their solutions. By George Moseley Murphy. 1960
#Section: Various 37
#Problem number: 1119.
restart;
ode:=(diff(y(x),x)^2+1)^(1/2)+a*diff(y(x),x) = y(x):
sol:=[dsolve(ode,y(x))]:
H1:=odetest(sol[1],ode):
H2:=odetest(sol[2],ode):
simplify((rhs-lhs)(map(`^`,isolate(H1,indets(H1,radical)[1]),2)));
simplify((rhs-lhs)(map(`^`,isolate(H2,indets(H2,radical)[1]),2)));

0

0

restart;        
#3054
#Book: Ordinary differential equations and their solutions. By George Moseley Murphy. 1960
#Section: Various 37
#Problem number: 1146.
restart;
ode:=ln(diff(y(x),x))+4*x*diff(y(x),x)-2*y(x) = 0:
sol:=[dsolve(ode,y(x))]:
H1:=odetest(sol[1],ode):
H2:=odetest(sol[2],ode):
simplify((rhs-lhs)(rationalize(map(exp,isolate(combine(H1),op(2,combine(H1)))))));
simplify((rhs-lhs)(rationalize(map(exp,isolate(combine(H2),op(2,combine(H2)))))));

0

0

restart;
#3129
#Book: Differential Equations, By George Boole F.R.S. 1865
#Section: Chapter 7
#Problem number: 8.
restart;
ode:=x = a*diff(y(x),x)+(diff(y(x),x)^2+1)^(1/2):
sol:=[dsolve(ode,y(x))]:
H1:=odetest(sol[1],ode):
H2:=odetest(sol[2],ode):
simplify((rhs-lhs)(map(`^`,isolate(H1,indets(H1,radical)[1]),2)));
simplify((rhs-lhs)(map(`^`,isolate(H2,indets(H2,radical)[1]),2)));

0

0

 

Download examples_of_odes_that_do_not_odetest_ac_pt1.mw

[edit. 23/12/2020] Partially addressing a followup example. (End-points can be examined separately.)

# 3647
restart;
ode :=diff(y(x),x)=2*(x*sqrt(y(x))-1)*y(x):
ic  :=y(0)=1:
sol :=dsolve([ode,ic]):
res :=odetest(sol,ode):
solve(simplify(res)) assuming real;
                 RealRange(Open(-1), infinity)

Here is another way that happens to work for this example.

Using allvalues on the RootOfs is a better/stronger idea. It's a shame that a single solve call cannot find the exact real solution directly, even with its explicit option (and possibly with some mechanism to denote realness).

restart;

F := -1 - y - exp(x);

-1-y-exp(x)

G := x^2 + y*(exp(x) - 1);

x^2+y*(exp(x)-1)

Ty:=eliminate({F,G},{y});

[{y = -1-exp(x)}, {-(exp(x))^2+x^2+1}]

remove(has,map(s->solve(s union Ty[1],explicit),
              {solve({G} union Ty[2])}), RootOf);

{{x = 0, y = -2}}

Download solve_exp_poly_ex.mw

There are also some slightly more general but uglier variants which utilize frontend (as if temporarily freezing the exp call) and pass an inequality to solve to denote realness.

There is the iscont command. Its Help page is linked from the "See Also" part of the discont command's Help page.

There will always be problematic examples, however.

restart;

f := piecewise(x < 1, x, -x);

f := piecewise(x < 1, x, -x)

iscont(f, x=-infinity..1);

true

iscont(f, x=-infinity..1, closed);

false

iscont(f, x=1..infinity);

true

iscont(f, x=1..infinity, closed);

true

restart;

g := piecewise(x <= 1, x, -x);

g := piecewise(x <= 1, x, -x)

iscont(g, x=-infinity..1);

true

iscont(g, x=-infinity..1, closed);

true

iscont(g, x=1..infinity);

true

iscont(g, x=1..infinity, closed);

false

 

Download iscont.mw

There is also fdiscont, which can be finicky but may offer some recourse for examples for which symbolic analysis is problematic. It doesn't go well on your piecewise example, though.

The first thing is that you have a syntax mistake. You have,
    S*`union`(T intersect R);
which ought to be,
    S union (T intersect R);
It's possible that was an implicit multiplication mistake made in 2D Input mode.

restart;

lign1 := S union (T intersect R);

`union`(S, `intersect`(R, T))

lign2 := (S union T) intersect (S union R);

`intersect`(`union`(R, S), `union`(S, T))

L1, L2 := eval([lign1, lign2],[`union`=`&or`, `intersect`=`&and`])[];

`&or`(S, `&and`(R, T)), `&and`(`&or`(R, S), `&or`(S, T))

Logic:-Equivalent(L1, L2);

true

Download logic_set.mw

There are several ways to do this. Here is but one of them,

restart

V := RandomTools:-Generate(variable(length = 4))

yhcm

{`~`[parse](StringTools:-Explode(V))[]}

{c, h, m, y}

NULL

Download CAP13CombinatoireQuestion_ac.mw

I'm not sure why you want them in a set at the end (instead of a list or Vector). When you put them into a set you may lose duplicates.

You can remove all output (including plots) from a worksheet as follows:
  Maple 2015:  File->Edit->Remove Output->From Worksheet   (Alt-e  v  w)
  Maple 2020:  Evaluate->Remove Output from Worksheet  (Ctl-d)

That message about storing large data mostly refers to the output of large Arrays/MatricesVectors/rtables, when they are printed as output. I don't know how to reuse such stored results upon Close/Re-open. (It is stored in some text-encoded reference in the XML of the .mw file, potentially large.)

The preference for the large-computation-autosave-thingy is in a popup that apepars when you click the "Confirmation Dialogs" button on the Tools->Options->Interface popup tab. 

If you are using Explore then the embedded plot will lose the axis and viewing-range properties you put on it using the right-click menus, whenever the plot is subsequently updated.

Instead, you can use the view option in the actual plotting command to fix the visible range so that it remains static for all updates of the Sliders..

You may also use the sprintf command can construct strings. I think that often looks more legible than a complicated cat call.

You can escape double-quotes within the format. There are various ways to do it, depending on whether you want to pass allmembers as name or "allmembers" as string.

When you parse the result the inner double-quotes should survive. (Of course, parsing these results reuires Property to be a member of module NODESteelProfiles_I .)

g := "NODESteelProfiles_I:-Property";                                              
                        g := "NODESteelProfiles_I:-Property"

sprintf("%s(%a)", g, "allmembers");

             "NODESteelProfiles_I:-Property("allmembers")"

sprintf("%s(\"%a\")", g, allmembers);

             "NODESteelProfiles_I:-Property("allmembers")"

sprintf("%s(\"%s\")", g, "allmembers");

             "NODESteelProfiles_I:-Property("allmembers")"

The inner double-quotes are escaped within the string results. You don't see that when your merely print it, but you would if your used lprint.

The subsindets command does syntactic substitution. That is mostly similar to how subs works, and as the Help page explains by default subsindets will utilize subs to perform the replacement.

It is intentional that subsindets does not do a full evaluation by default. That allows multiple syntactic substitutions and structural manipulations to be performed in sequence.

You can compare subsindets with evalindets. You could also compare with calling the indexed command name subsindets[eval].

Entering an expression at the top-level does an evaluation (unless you use special syntax to control that). That's true even if done on something that subsindets or subs had returned unevaluated. It's also true if the expression is used for an assignment statement.

There should be nothing highly surprising in the following:

restart;

A := int(f(x), x);

int(f(x), x)

B := subsindets(A, specfunc(anything,f), u->op(u)^2);

int(x^2, x)

B;

(1/3)*x^3

eval(B, 1);

int(x^2, x)

evalindets(A, specfunc(anything,f), u->op(u)^2);

(1/3)*x^3

subsindets[eval](A, specfunc(anything,f), u->op(u)^2);

(1/3)*x^3

Download subsindets_evaluation.mw

As for int and your example involving exp(various ln calls, etc) it is much easier to snipe than to code. It's a difficult subject and there is no perfect algorithm for discerning when and whether to simplify all possible examples that might benefit as well as succeed in decent time. There is always room for improvement.

It seems to me that there are two kinds of issue worth considering here. One is the construction (binning, etc) of the data, and another is the plotting and visual rendering.

I'd like to look at the first part later, which I think could be done with some efficient procedure(s). There may be some related bits of functionality within the ImageTools:-Scale command. But I don't have time to study those R commands at the moment.

Here are a couple of alternatives for the plotting/rendering part, using techniques that are actually 2D.

You might still experiment with the nb size, naturally.

restart:

interface(version);

`Standard Worksheet Interface, Maple 2020.1, Linux, June 8 2020 Build ID 1474533`

with(Statistics):

UseHardwareFloats := false:

N := 10^4:
A := Sample(RandomVariable(BetaDistribution(2, 6)), N):
B := Sample(RandomVariable(BetaDistribution(6, 2)), N):

nb := 50:

mA := min(A):
hA := Range(A)/(nb-1):
mB := min(B):
hB := Range(B)/(nb-1):

cA := floor~((A-~mA)/~hA)+~1:
cB := floor~((B-~mB)/~hB)+~1:

NP := Matrix(nb$2, 0):
for n from 1 to N do
  NP[cA[n], cB[n]] := NP[cA[n], cB[n]]+1
end do:

NP:
 

# The OP's original, a 3D plot (be careful not to rotate it...)
# This is large, unweildy, and at large dimensions makes the GUI
# sluggish. In the worst case inadvertant mouse-selection may crash...

DPmat := plots:-matrixplot(
  NP,
  heights=histogram,
  colorscheme=["Blue", "White", "Red"],
  orientation=[270, 0, 0],
  style=patchnogrid,
  lightmodel=none,
  labels=["A", "B", ""],
  axis[1]=[tickmarks=[nb+1=max(B), 1=mB]],
  axis[2]=[tickmarks=[nb+1=max(A), 1=mA]]
):
DPmat;

# This produces a 2D structure akin to what the `densityplot` command
# returns.
# The values get interpolated (because the binned data is smaller than
# the dimensions at which we render here. That's not so nice because the
# effect is a blurred rendering.
# But this computation is a nice intermediate and very easy way to
# apply the colorscheme, and below we rip out the color Array from it.

DP:=plots:-surfdata(
  NP,
  mB..max(B), mA..max(A), dimension=2,
  colorscheme=["Blue", "White", "Red"],
  style=patchnogrid,
  labels=["A", "B"],
  axis[1]=[tickmarks=[mB, max(B)]],
  axis[2]=[tickmarks=[mA, max(A)]],
  size=[475,450]
):
DP;

RAW:=ImageTools:-Rotate(op([2],indets(DP,specfunc(anything,COLOR))[1]),'left'):

DPimg := plot(mB..max(B), mB..max(A),
     background=ImageTools:-Scale(RAW,1..400,method=nearest),
     size=[475,450], axes=boxed,
     labels=["A", "B"],
     axis[1]=[tickmarks=[mB, max(B)]],
     axis[2]=[tickmarks=[mA, max(A)]]):
DPimg;

length(DPmat), length(DP), length(DPimg);

1970649, 10408, 5425

ImageTools:-Embed(ImageTools:-Scale(RAW,1..400,method=nearest));

 

2D_density_plot_acc.mw

First 101 102 103 104 105 106 107 Last Page 103 of 336