## 21438 Reputation

15 years, 116 days

## ideas...

Here are a few ideas for inspiration.

The computation of
n_error[0]:=1.5-newt(1.5);
does not make much sense, if it is intended to mean a comparsion of x[0] and f(x[0]).

The computations of
nerror[count]:=abs(x[count]-x[count-1]);
make sense, but aren't very meaningful as estimates of error in f.

If you have 10 x-values, then you only have 9 incremental changes. There is no first n_error[0] really (or no last one, depending how you want to write it down).

You might want to end the loop if the x-increment gets too small, or if the f(x) evaluation gets acceptably close to zero.

There's not much benefit in storing rt as well as x.

I'm not sure that DataFrames are the best for the task, or at least I'd suggest that the given Append use is a little awkweard. Here's one way with a DataFrame augmented within the loop, and one without.

 > restart;
 > newt := x -> evalf(x - f(x)/D(f)(x)):
 > f:= x -> x^6-2; # function to analyze

 > x[0] := 1.5;

 > xtol,ftol := 1e-10, 1e-10;

 > DF := DataFrame( <> ): DF[1,2],DF[1,3] := ``, f(x[0]):
 > for count from 1 to 10 do    x[count] := newt(x[count-1]);    xincr := abs(x[count]-x[count-1]);    fval := abs(f(x[count]));    DF:=Append(DF,DataSeries(),mode=row); until xincr < xtol or fval < ftol:
 > DataFrame(DF, columns=[x, abs(x_incr), `f `(x)]);

 > restart; newt := x -> evalf(x - f(x)/D(f)(x)): f:= x -> x^6-2: # function to analyze x[0] := 1.5: xtol,ftol := 1e-10, 1e-10: M := Array(0..0,1..3,[x[0],"",f(x[0])]): for count from 1 to 10 do    x[count] := newt(x[count-1]);    xincr := abs(x[count]-x[count-1]);    fval := abs(f(x[count]));    M(count+1, ..) := ; until xincr < xtol or fval < ftol: #M; W:=DataFrame(Matrix(M), columns=[x, abs(x_incr), ''f''(x)]);

 > Tabulate(W, width=600, widthmode=pixels,             weights=[3, 15, 15, 15]):
 >

## name?...

It has to be either a name or a string, since the literal input literal 46th by itself isn't valid Maple syntax for anything. That's also why your string won't parse.

It would be better if you explained clearly what you mean when you write that you want to "get 46th". What do you mean by "get"? Do you mean you want to be able to display something that looks like that, without the double-quotes showing? If so then in what context? Do you mean that you want a Maple expression? What do you mean by 46th, without the string quotes?

Here is one way to obtain it as a name.
convert(46,compose,ordinal,name)
That prints in italics.

The following produces a name that prints in the Standard GUI in upright Roman.
nprintf(`#mn(%a);`,convert(46,ordinal));

## one way...

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

 > k(10);

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

 > sol(parameters=[Afound]);

 > k(10);

 > k(10, Afound);

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

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

 >

## Import...

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

## something...

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

 > # 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');

 >

## comment...

 > restart
 > with(Units:-Simple):
 >

 > restart
 >

## evalf(Int(...))...

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

 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.

## normalize, then scale...

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

 >

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,
```

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```

## verify...

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
```

## ideas...

```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:
```

## no LaTeX interpreter...

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(\"ä\");`,                    "ufe von ", e(t), " und ",                    `#msub(mover(mi("ϵ"),mi(".")),mo("p"));`(t)));

## a couple more...

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]
```

## as typeset strings...

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;

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

 >

## assigned...

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
```

## ExcelTools:-Export, list or Vector...

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.

 4 5 6 7 8 9 10 Last Page 6 of 241
﻿