acer

32692 Reputation

29 Badges

20 years, 76 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Here is one way. There are others. I think that it's useful that these render in upright Roman rather than as italics.

restart:

interface(rtablesize=20):

f:=(x,t)->x*t;
g:=(x,t)->x^2*t;

proc (x, t) options operator, arrow; x*t end proc

proc (x, t) options operator, arrow; x^2*t end proc

B:=Matrix([[x,t,"f(x,t)","g(x,t)"],
         seq(seq([i,j,f(i,j),g(i,j)],
                 j=0.125..0.875, 0.25),
             i=0.125..0.875,0.25)]):

B[1,..]:=map(p->nprintf(`#mi(%a);`,p),B[1,..]):
B[2..,4]:=map(p->nprintf(`#mn(\"%1.3e\");`,p),B[2..,4]):
B;

Matrix(17, 4, {(1, 1) = `#mi("x")`, (1, 2) = `#mi("t")`, (1, 3) = `#mi("f(x,t)");`, (1, 4) = `#mi("g(x,t)");`, (2, 1) = .125, (2, 2) = .125, (2, 3) = 0.15625e-1, (2, 4) = `#mn("1.953e-03")`, (3, 1) = .125, (3, 2) = .375, (3, 3) = 0.46875e-1, (3, 4) = `#mn("5.859e-03")`, (4, 1) = .125, (4, 2) = .625, (4, 3) = 0.78125e-1, (4, 4) = `#mn("9.766e-03")`, (5, 1) = .125, (5, 2) = .875, (5, 3) = .109375, (5, 4) = `#mn("1.367e-02")`, (6, 1) = .375, (6, 2) = .125, (6, 3) = 0.46875e-1, (6, 4) = `#mn("1.758e-02")`, (7, 1) = .375, (7, 2) = .375, (7, 3) = .140625, (7, 4) = `#mn("5.273e-02")`, (8, 1) = .375, (8, 2) = .625, (8, 3) = .234375, (8, 4) = `#mn("8.789e-02")`, (9, 1) = .375, (9, 2) = .875, (9, 3) = .328125, (9, 4) = `#mn("1.230e-01")`, (10, 1) = .625, (10, 2) = .125, (10, 3) = 0.78125e-1, (10, 4) = `#mn("4.883e-02")`, (11, 1) = .625, (11, 2) = .375, (11, 3) = .234375, (11, 4) = `#mn("1.465e-01")`, (12, 1) = .625, (12, 2) = .625, (12, 3) = .390625, (12, 4) = `#mn("2.441e-01")`, (13, 1) = .625, (13, 2) = .875, (13, 3) = .546875, (13, 4) = `#mn("3.418e-01")`, (14, 1) = .875, (14, 2) = .125, (14, 3) = .109375, (14, 4) = `#mn("9.570e-02")`, (15, 1) = .875, (15, 2) = .375, (15, 3) = .328125, (15, 4) = `#mn("2.871e-01")`, (16, 1) = .875, (16, 2) = .625, (16, 3) = .546875, (16, 4) = `#mn("4.785e-01")`, (17, 1) = .875, (17, 2) = .875, (17, 3) = .765625, (17, 4) = `#mn("6.699e-01")`})

 

Download sci_not.mw

The command assigned provides functionality that can be used to test whether a value is being used as index for a given table (ie, that the table reference evaluates to something else).

restart;                                                                           

L["hello"]:=funny:

assigned(L["hello"]);

                true

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.

First 104 105 106 107 108 109 110 Last Page 106 of 340