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

Using Maple 2020.1

restart;

url := "https://www.gw-openscience.org/GW150914data/P150914/fig1-observed-H.txt":


And it can be done simply.

M := ImportMatrix(url,source=Matlab,mode=ascii,skiplines=1):

plot(M);

Download import_url.mw

There are a few different effects.

There's the collecting of terms in the denominator, which I'm guessing is important for you.

And then there's the ordering of terms in products and sums. I'm supposing that you care more about the order of terms in sums, as that can affect whether there are unwanted leading minus-signs.

This is close, except for the order of the multiplicands (X__1-I__11) and (X__2-I__22).

restart;

a:=-(I__22-X__2)/(I__11*I__22-I__11*X__2-I__12*I__21-I__22*X__1+X__1*X__2);

-(I__22-X__2)/(I__11*I__22-I__11*X__2-I__12*I__21-I__22*X__1+X__1*X__2)

# Note that we didn't input `b` explicitly.
# If we had it would have helped and made some steps
# unnecessary. But we want the `sort` effects without
# that, hence `b` form was not entered explicitly.

sort(numer(a)/collect(denom(a),[I__12],simplify),
     [I__21,I__22],'ascending');

(X__2-I__22)/((X__2-I__22)*(X__1-I__11)-I__12*I__21)

 

Download simplif_sort_ex.mw

restart

with(Units:-Simple):

I__RMS__T := int((18*Unit('A')+9*t*Unit('A')/(.9*Unit('s')))^2, t = 0.1e-1*Unit('s') .. 10*Unit('s'))

54570.07529*Units:-Unit(A^2*s)

restart

I__RMS__T := int((18*Unit('A')+9*t*Unit('A')/(.9*Unit('s')))^2, t = 0.1e-1*Unit('s') .. 10*Unit('s'))

54570.07530*Units:-Unit(A^2*s)

Download test_units_int_ac.mw

Change the evalf(int(...)) calls to evalf(Int(...)) with capitalized Int.

[edit] On my machine that change alone is enough to bring the timing for the cited problematic example down to under 2 seconds. [end of edit]

The lowercase int attempts symbolic integration, and if that fails then wrapping evalf call induce numeric integration. But you may not wish to expend unnecessary effort on the symbolic attempt.

The capitalized Int is an inert placeholder, and evalf(Int(...)) goes directly to an attempt at numeric integration.

You could normalize the vector magnitude (according to the max over the given ranges, say), to get hue values between 0 and 1, and then scale by a factor to avoid the roll-over in the upper end of the hue.

Or you could cook up a similar thing for RGB instead of HSV.

There are other ways, but this could give you some ideas to play with.

restart;

plots:-fieldplot([1, y^2 + x], x = -10 .. 10, y = -6 .. 6,
                 fieldstrength = fixed,
                 color = COLOR(HSV, 0.833*abs(y^2+x+1)/(36+10+1),
                                    1.0, 1.0));

plots:-fieldplot([1, y^2 + x], x = -10 .. 10, y = -6 .. 6,
                 fieldstrength = fixed,
                 color = COLOR(HSV, 0.833*sqrt(((y^2+x)^2+1)/((6^2+10)^2+1)),
                                    1.0, 1.0));

huemin:=0.0: huemax:=0.5:

plots:-fieldplot([1, y^2 + x], x = -10 .. 10, y = -6 .. 6,
                 fieldstrength = fixed,
                 color = COLOR(HSV, huemin+(huemax-huemin)*sqrt(((y^2+x)^2+1)/((6^2+10)^2+1)),
                                    1.0, 1.0));

plot3d(0.833*sqrt(((y^2+x)^2+1)/((6^2+10)^2+1)), x = -10 .. 10, y = -6 .. 6,
       color = COLOR(HSV, 0.833*sqrt(((y^2+x)^2+1)/((6^2+10)^2+1)),
                                    1.0, 1.0),
       labels=[x,y,HUE]);

 

Download color_formula.mw

I included that surface plot3d to illustrate that one of those formulas make it behave something like this:

plot3d(LinearAlgebra:-Norm(<[1,y^2+x]>,2),x=-10..10,y=-6..6,
       colorscheme=["zgradient",[Red,Magenta],colorspace="HSV"]);

And I chose 0.833 for the scaling because that approximates magenta as an upper value for hue.

ColorTools:-Color("HSV", "Magenta")[];
     0.8333333333, 1.000000000, 1.00000000

Here is one way,

V1 := Vector[column](8, [1,2,2,1,3,A,B,1/(A + B)^2]):
V2 := Vector[column](8, [1,2,2,1,3,A,B,1/(A^2 + 2*A*B + B^2)]):

verify( V1, V2, 'Vector(simplify)' );

                 true

How about,

foo:=proc(ode::{`=`, set(`=`), list(`=`)},func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

Or, shorter,

foo:=proc(ode::{`=`, {set,list}(`=`)},func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

Or, excluding the empty cases,

foo:=proc(ode::{`=`, And({set,list}(`=`),Not(identical([],{})))},
          func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

There is no direct LaTeX parser in Maple.

But there is support for mixed plaintext and marked up (typeset) 2D Math in plot titles, captions, legends, etc.

You can enter the 2D Math directly, manually, by operating in 2D Math mode (Ctl-R) and selecting special characters, accents, etc, from the left palettes.

Or you can enter it all in plaintext code using a sort of XML/HTML markup (undocumented, but not overly difficult). That can be accomplished programatically. For example,

plot(sin(x), x=5..20, view=-2..2, size=[500,300],
     axis[1]=[gridlines=[seq(i,i=5..20,5)]],
     axis[2]=[gridlines=[$-2..2]], axes=boxed,
     title=typeset("Verl", `#mo(\"&auml;\");`,
                   "ufe von ", e(t), " und ",
                   `#msub(mover(mi("&varepsilon;"),mi("&period;")),mo("p"));`(t)));
 

Download plot_typemk.mw

 

For fun, a few more ways that ought to run in Maple 2017.2 (the second is rather slower).

restart;
f := x->18*log10(x):
g := x->1/2*x^3-8*x^2+69/2*x-27:

[fsolve(f-g, 0..12, maxsols=5)];

     [0.03721465484, 1.000000000, 4.506164928, 10.00000000]

sort(remove(type,[solve(f(x)-1.0*g(x))], nonreal));

         [0.03721465485, 1., 4.506164928, 10.00000000]

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]);

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