acer

32582 Reputation

29 Badges

20 years, 33 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Here is one way. You can either call `k` with a single t-value, or with both a t-value and a new a-value.

After the plotting, you can call `k` at whatever t-values you wish.

restart;

xodephi := {diff(x(t), t) = 16250.25391*(1 - (487*x(t))/168 + 4*Pi*x(t)^(3/2) + (274229*x(t)^2)/72576 - (254*Pi*x(t)^(5/2))/21 + (119.6109573 - (856*ln(16*x(t)))/105)*x(t)^3 + (30295*Pi*x(t)^(7/2))/1728 + (7.617741607 - 23.53000000*ln(x(t)))*x(t)^4 + (535.2001594 - 102.446*ln(x(t)))*x(t)^(9/2) + (413.8828821 + 323.5521650*ln(x(t)))*x(t)^5 + (1533.899179 - 390.2690000*ln(x(t)))*x(t)^(11/2) + (2082.250556 + 423.6762500*ln(x(t)) + 33.2307*ln(x(t)^2))*x(t)^6)*x(t)^5, diff(xphi(t), t) = 5078.204347*x(t)^(3/2), x(0) = 0.03369973351, xphi(0) = a}:  #xphi(10.92469316) = 0}:

sol := dsolve(xodephi, parameters=[a], numeric):

#
# Calling k(anything, numeric) sets the `a` parameter
# to the second argument.
#
# Calling k(anything, nonnumeric)
#      or k(nonnumeric, anything)
#      or k(nonnumeric)
# returns unevaluated.
#
# Calling k(numeric) computes xphi at that value,
# using the current parameter setting.
#
# Calling k(numeric, numeric) computes xphi at the 1st argument,
# after setting the `a` parameter to the second argument.
#
k := proc(tt, A)
  if nargs=2 then
    if A::numeric and A<>eval(':-a',sol(parameters)) then
      sol(parameters=[A]);
    elif not A::numeric then
      return 'procname'(args);
    end if;
  end if;
  if not tt::numeric then return 'procname'(args); end if;
  eval(xphi(':-t'), sol(tt));
end:

 

k(10, 100);

HFloat(504.6805374189861)

k(10);

HFloat(504.6805374189861)

Afound := fsolve(k(10.92469316, A));

-467.1843838

sol(parameters=[Afound]);

[a = -467.1843838]

k(10);

HFloat(-62.503861924194105)

k(10, Afound);

HFloat(-62.503861924194105)

#plot( k(10, AA), AA=-500..100, size=[200,200] );

plots:-display(Array([
  plots:-odeplot(sol, [t,xphi(t)], t=0..11),
  plots:-odeplot(sol, [t,k(t)], t=0..11, labels=["",xphi]),
  plot(k(t), t=0..11, labels=["",xphi]) ]), size=[200,200]);

 

 

 

 

 

seq(k(i), i=0..11.0, 0.5);

-467.1843838, HFloat(-451.35284337254996), HFloat(-435.26421792219355), HFloat(-418.9024575949357), HFloat(-402.2497188915288), HFloat(-385.2857910231282), HFloat(-367.98805180702436), HFloat(-350.3311515250434), HFloat(-332.2859029154144), HFloat(-313.8186382395069), HFloat(-294.89050202705636), HFloat(-275.45611970121246), HFloat(-255.46131378253165), HFloat(-234.84114277829883), HFloat(-213.51691387261195), HFloat(-191.39019284210806), HFloat(-168.33651233737638), HFloat(-144.1927949775133), HFloat(-118.73944335663056), HFloat(-91.66557267955444), HFloat(-62.503861924194105), HFloat(-30.486336758748322), HFloat(5.845321943206811)

seq([i, k(i)], i=0..11.0, 0.5);

[0, -467.1843838], [.5, HFloat(-451.35284337254996)], [1.0, HFloat(-435.26421792219355)], [1.5, HFloat(-418.9024575949357)], [2.0, HFloat(-402.2497188915288)], [2.5, HFloat(-385.2857910231282)], [3.0, HFloat(-367.98805180702436)], [3.5, HFloat(-350.3311515250434)], [4.0, HFloat(-332.2859029154144)], [4.5, HFloat(-313.8186382395069)], [5.0, HFloat(-294.89050202705636)], [5.5, HFloat(-275.45611970121246)], [6.0, HFloat(-255.46131378253165)], [6.5, HFloat(-234.84114277829883)], [7.0, HFloat(-213.51691387261195)], [7.5, HFloat(-191.39019284210806)], [8.0, HFloat(-168.33651233737638)], [8.5, HFloat(-144.1927949775133)], [9.0, HFloat(-118.73944335663056)], [9.5, HFloat(-91.66557267955444)], [10.0, HFloat(-62.503861924194105)], [10.5, HFloat(-30.486336758748322)], [11.0, HFloat(5.845321943206811)]

 

Download ds_param_easy.mw

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.

First 102 103 104 105 106 107 108 Last Page 104 of 338