acer

21403 Reputation

29 Badges

15 years, 111 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@BrettKnoss The second example doesn't need the DataFrame, I just threw it in at the end. It only needs M, a Matrix which stores the data.

The Matrix M gets extended at each iteration by use of the round-bracket "programmer's indexing". The seems simpler than Append on a DataFrame.

@Carl Love From the OP's edited description it reads as if the bug was in his own code, which had a mismatched type declaration on the local variable to which the FetchAll result were assigned.

@DJJerome1976 It's always better to explain what you're really after up front.

restart;

temp := "This is the %s object with a certain property.":

sprintf(temp, convert(46,ordinal));

"This is the 46th object with a certain property."

nprintf(temp, convert(46,ordinal));

`This is the 46th object with a certain property.`

nprintf(`#mn(%a);`,sprintf(temp, convert(46,ordinal)));

`#mn("This is the 46th object with a certain property.");`

Download printf_s.mw

@matviiv10 Please don't post followup queries about this code in a separate Question.

@tomleslie This inlines here, for me.

It might be due to supplying the size option. (I usually/always use that, for arrays of plots, and inlining those here usually/always works for me.)

restart;
N:=15:
# f:=(x,y) -> (Re,Im)(sin(x+I*y):
f:=(x,y) -> (Re,Im)(ln(1+I*(1+x+I*y)^2/9)):
P:=plot([seq([x,y,x=0..1],y=0..1,1/N), seq([x,y,y=0..1],x=0..1,1/N)]):
plot([seq([f(x,y),x=0..1],y=0..1,1/N), seq([f(x,y),y=0..1],x=0..1,1/N)],scaling=constrained):

# Using plottools:-transform
with(plottools):with(plots):
F := transform((x, y) -> [f(x,y)]):

plots:-display(<P|F(P)>, scaling=constrained, size=[400,400]);

 

 

 

 

 

 

Download Vector_of_plots_size.mw

I wish that they'd fix the backend to utilize PNG instead of JPG/other for the exported plot images, and also to not render gridlines when the plot structure doesn't contain it.)

@Carl Love I don't disagree with you.

I was wondering why Tom removed the units from the integration range, while not otherwise adjusting for that dimension.

I figured I might possibly have misinterpreted the goal, which was not stated in words -- only because I didn't really understand the OP's first attempt. However the OP's two attempts did both have units on the integration range, so originally I figured that the intention was something in units A^2*s.

What do you want to happen if the parameter `a` value is changed, between computing the various xphi values and any subsequent call to `k`?

Do you want the calls to `k` to get the prior values for xphi, or to recompute using the later parameter setting?

@tomleslie It wasn't clear (to me, at least) whether the answer is supposed to be in terms of units A^2 or A^2*s. Perhaps the target answer was supposed to be obvious?!

@mmcdara The padding value is in pixels, afaik. (Well, pixels in the usual sense, ie. at 100% zoom. Let's not get into dot-pitch.)

The example mostly works for me in my Maple 2020 GUI. Some things work imperfectly when rendered by this site's considerably older backend engine.

@zphaze You showed two attempts.

The first doesn't make sense to me.

The primary problem with the second is the integrand itself, which as written is already problematic in the Units:-Standard framework, even outside of the int call. The Units:-Simple subpackage was designed with one of its principal themes being to allow that kind of tacit dimension for an unassigned name such as the t in your second example's integrand.

If you don't want the strictures of the Units:-Standard package then don't load it.

You can call it whatever you want.

After normalizing to 0..1 (and prior to scaling), you could subtract from 1.
 

restart;

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

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

plots:-display(Array([P2,P1]),size=[400,400]);

 

 

 

 

 

Download color_formula_rev.mw

@mmcdara I like your Answer (and Tom's, too). I especially like the rowspan use.

For fun, here I get black 2D Input, with numeric formatting of the last column, and alternating background color varying with the k sequence index.

(I don't know why this one doesn't render as nicely as yours on Mapleprimes. It does look much better in the Maple GUI. Was yours a screenshot?)

restart:

with(DocumentTools:-Layout):

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

val := [seq(i,i=0.125..0.875,0.25)]:
n     := numelems(val):
val_x := [seq(op(val[[k$n]]), k=1..n)]:
val_t := op~([val$n]):
val_f := f~(val_x, val_t):
val_g := g~(val_x, val_t):
res  := convert([val_t, val_f, val_g], Matrix)^+:

res[..,3] := map(p->nprintf(`#mn(\"%1.4e\");`,p),res[..,3]):

cols := Vector[row](4, ["x", "t", "f(x, t)", "g(x, t)"]):

TDI := style=TwoDimInput: FC := fillcolor=piecewise(irem(k,2)=0,"#eeeeff","#eeffee"):
W := Table(seq(Column(), j=1..n), widthmode=pixels, width=500, alignment=center,
           Row( seq( Cell(cols[j], fillcolor="LightGray"), j=1..4) ),
           seq(op([Row(Cell( Textfield(Equation(val[k], TDI)), FC, rowspan=4, padding=50),
                       seq(Cell( Textfield(Equation(res[1+n*(k-1), j], TDI)), FC ),
                           j=1..3)),
                   seq(Row(seq(Cell( Textfield(Equation(res[i, j], TDI)), FC ),
                               j=1..3)),
                       i=2+n*(k-1)..n+n*(k-1))]),
               k=1..n)):
DocumentTools:-InsertContent(Worksheet(Group(W))):

 

x

t

f(x, t)

g(x, t)

.125

.125

0.15625e-1

`#mn("1.9531e-03")`

.375

0.46875e-1

`#mn("5.8594e-03")`

.625

0.78125e-1

`#mn("9.7656e-03")`

.875

.109375

`#mn("1.3672e-02")`

.375

.125

0.46875e-1

`#mn("1.7578e-02")`

.375

.140625

`#mn("5.2734e-02")`

.625

.234375

`#mn("8.7891e-02")`

.875

.328125

`#mn("1.2305e-01")`

.625

.125

0.78125e-1

`#mn("4.8828e-02")`

.375

.234375

`#mn("1.4648e-01")`

.625

.390625

`#mn("2.4414e-01")`

.875

.546875

`#mn("3.4180e-01")`

.875

.125

.109375

`#mn("9.5703e-02")`

.375

.328125

`#mn("2.8711e-01")`

.625

.546875

`#mn("4.7852e-01")`

.875

.765625

`#mn("6.6992e-01")`

 

 

 

Layout_1_ac.mw

@mmcdara If you are using Maple 2015, or if the OP is using Maple 17, then it is significantly faster to do it like so:

restart;

kernelopts(version);

`Maple 17.02, X86 64 LINUX, Sep 5 2013, Build ID 872941`

dsys:={diff(n(t),t)=-2*(n(t)-N)+(u(t)-abs(M)*exp(I*phi))*exp(-2*I*omegap*t/lambda)+conjugate((u(t)-abs(M)*exp(I*phi))*exp(-2*I*omegap*t/lambda)),diff(u(t),t)=-2*(1-I*delta)*u(t)+2*(n(t)-N)*exp(-2*I*omegap*t/lambda)+2*abs(M)*exp(I*phi)}:

dsys := dsys union {n(0)=0,u(0)=0}:
undefined_quantities := indets(dsys, name):
params := convert(undefined_quantities minus {t}, list)

Warning, inserted missing semicolon at end of statement

[M, N, delta, lambda, omegap, phi]

res1 := dsolve(dsys union {n(0)=0,u(0)=0}, numeric, parameters=params);

"res1:=proc(x_rkf45) ... end proc"

# example: the moving param is M
f := proc(s, m)
  local data:
  if rhs(res1(parameters)[1])<>m then
    data := params=~[m, 1, 1, 1, 1, 1]:
    res1(parameters=data):
  end if;
  eval(Re(n(t)), res1(s))
end proc:

CodeTools:-Usage( plot3d('f(s, m)', m=1..2, s=0..1, labels=['M', s, 'n(t)']) );

memory used=331.55MiB, alloc change=36.00MiB, cpu time=2.71s, real time=2.72s

 

Download Try_This_2_ac.mw 

In older versions there is (unnecessary, unwanted) wiping of cached information that occurs even when the parameters are set to their same, extant values. This causes considerable inefficiency, that can be avoid by the simple check that I show here. I believe that inefficiency is fixed in recent versions.

@ahmeng From my Maple 2017.2 for 64bit Linux,

restart;

kernelopts(version);

`Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392`

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

# This use of maxsols is not documented for univariate
# non-polynomial case, but it works for me regardless.
#
[fsolve(f-g, 0..12, maxsols=5)];

[0.3721465484e-1, 1.000000000, 4.506164928, 10.00000000]

# First call to this below is not fast.
# Duplicating the call is fast (but only due to some
# internal remembering of results).
#
CodeTools:-Usage( sort(remove(type,[solve(f(x)-1.0*g(x))], nonreal)) );

memory used=395.22MiB, alloc change=6.01MiB, cpu time=10.52s, real time=10.52s, gc time=435.14ms

[0.3721465485e-1, 1., 4.506164928, 10.00000000]

 

Download isect.mw

When solve detects the explicit float coefficiant that I introduced into the example it tries to resolve the ensuing approximate RootOfs (via evalf, etc). So it's similar to evalf after allvalues. For me it is not fast on first attempt (and being fast upon repeats means nothing here -- it just remembers some results internally).

The maxsols for fsolve (univariate non-polynomial) usage can be traced through to a iterated use of Rootfinding:-Nextzero, which is yet another approach that one could do up manually.
   showstat(fsolve::scalarmultiple)
It is true that the maxsols option is not documented for the univariate nonpolynomial case. But it is documented for the univariate polynomial case. Your screenshot doesn't show even that, though, since it seems you are citing ?fsolve and not ?fsolve,details .

In your example, L is a table and not a list.

5 6 7 8 9 10 11 Last Page 7 of 450