acer

33492 Reputation

29 Badges

21 years, 65 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

A great deal of the computations done by the Finance package are made via external calls to a (bundled) Quantlib (dynamic shared) library.

But -- even if this is the case for the path generation in question -- it may be necessary to identify the particular version number of the bundled Quantlib library in order to get the right answer.

acer

What methodology are you using to "recover the structure of my worksheet by working on XMLElements"?

Are you using the XMLTools package? Are you reading in the .mw file, so that it becomes a large nested function call?

Are you saying that you just want to remove any qualification by Font, so as to be left with just a Textfield?

It's not clear to me how you are doing the work, so far, and so it's hard to make a concrete suggestion.

(It may or may not be of interest to you, but I have been working on a tool to scrape a .mw file so as to extract all its contents. Ie, all code to 1D Maple Notation, all Text to comment strings, optionally all Output to expressions saved aside, and even all unassigned rendered plots to actual PLOT structures save aside. And so on. I can't tell whether this is of possible use to you as I can't tell whether your target is plainext or rather just a modified .mw file, etc.) 

acer

You already asked this question in another post. This is spam.

acer

@Mac Dude These are not new features. I've seen these kinds things demonstrated in the Std GUI since very early in its existence. The example I gave can be created with the same steps in my Maple 15.01 for Windows 64bit as in my Maple 2015.1 on the same platform.

Here is is, done in Maple 15.01.

inlined1501.mw

Here is a revision with the style of 2D Math output customized to black (Format-Styles from the main menubar), and the text containing inlined 2D Math put into a GUI Table with custon properties.

Download inlinedmathtable.mw

Sure, the rtable subtype of the result returned by SparseLU:-Solve can be made to match that of the RHS of the linear system. See the code revision below.

As for the zeroes of a sparse Matrix, it depends on how you contruct the Matrix. If you used the Matrix command then, yes, you need to specify all the scanned data. But I only used the command because it was convenient. You can also create a sparse Matrix with the syntax M:=Matrix(3,3,storage=sparse,datatype=float[8]) where no entries are initially assigned. You can then start assigning entries, like M[2,4]:=3.12, say. Or you can import the whole sparse Matrix from a file with special formatting, using ImportMatrix.


> 

restart:

> 

SparseLU:=module()

> 

   option package;

> 

   export LU,Solve,Free;

> 

   local extlib, Anz, NumericA, numrows;

> 

   LU:=proc(M::Matrix(:-storage=:-sparse,:-datatype=:-float[8],

> 

                      :-order=:-Fortran_order))

> 

      local extfun, numcols;

> 

      if extlib='extlib' then

> 

         extlib:=ExternalCalling:-ExternalLibraryName("linalg",':-HWFloat');

> 

      end if;

> 

      extfun:=ExternalCalling:-DefineExternal(':-hw_SpUMFPACK_MatFactor',

> 

                                              extlib);

> 

      (numrows,numcols):=op(1,M);

> 

      (Anz,NumericA):=extfun(numrows,numcols,M);

> 

      NULL;

> 

   end proc:

> 

   Solve:=proc(numrows::posint, V::{Matrix,Vector})

> 

      local B,extfun,res;

> 

      if type(V,'Matrix'(':-storage'=':-sparse',':-datatype'=':-float[8]',

> 

                         ':-order'=':-Fortran_order')) then

> 

         B:=V;

> 

      else

> 

         B:=Matrix(V,':-storage'=':-sparse',':-datatype'=':-float[8]',

> 

                   ':-order'=':-Fortran_order');

> 

      end if;

> 

      if extlib='extlib' then

> 

         extlib:=ExternalCalling:-ExternalLibraryName("linalg",':-HWFloat');

> 

      end if;

> 

      extfun:=ExternalCalling:-DefineExternal(':-hw_SpUMFPACK_MatMatSolve',

> 

                                              extlib);

> 

      if not(Anz::posint and NumericA::posint and numrows::posint) then

> 

          error "invalid factored data";

> 

      end if;

> 

      res:=extfun(numrows,op([1,2],B),Anz,NumericA,B);
      if rtable_options(res,':-subtype') <> rtable_options(V,':-subtype') then
          res := convert(res,rtable_options(V,':-subtype'));
      end if;
      res;

> 

   end proc:

> 

   Free:=proc()

> 

      local extfun;

> 

      if not NumericA::posint then

> 

         error "nothing valid to free";

> 

      end if;

> 

      if extlib='extlib' then

> 

         extlib:=ExternalCalling:-ExternalLibraryName("linalg",':-HWFloat');

> 

      end if;

> 

      extfun:=ExternalCalling:-DefineExternal(':-hw_SpUMFPACK_FreeNumeric',

> 

                                              extlib);

> 

      extfun(NumericA);

> 

      NumericA:=-1;

> 

      NULL;

> 

   end proc:

> 

end module:

> 

MM:=Matrix([[0.,0.,-25.],[-53.,-7.,0.],[0.,-70.,0.]],

> 

           ':-storage'=':-sparse',':-datatype'=':-float[8]'):

> 

with(SparseLU):

> 

LU(MM);

> 

VV:=Vector([1,1,1]);

VV := Vector(3, {(1) = 1, (2) = 1, (3) = 1})

> 

ans:=Solve(3,VV);

ans := Vector(3, { sparse_data }, datatype = float[8], storage = sparse)

> 

rtable_options(ans,':-subtype');

Vector[column]

> 

LinearAlgebra:-Norm(MM.ans - VV);

0.

> 

VV:=LinearAlgebra:-RandomMatrix(3,2,':-datatype'=':-float[8]');

VV := Matrix(3, 2, {(1, 1) = -53.0, (1, 2) = 40.0, (2, 1) = 21.0, (2, 2) = 97.0, (3, 1) = -25.0, (3, 2) = 43.0}, datatype = float[8])

> 

ans:=Solve(3,VV);

ans := Matrix(3, 2, { sparse_data }, datatype = float[8], storage = sparse)

> 

rtable_options(ans,':-subtype');

Matrix

> 

LinearAlgebra:-Norm(MM.ans - VV);

0.


Download sparselu.mw

@ClearBlueSky In my followup S is a formula for approximating MTBF. It is devoid of LambertW and GAMMA related functions.

So, you would need a function to compute the finite summation Sum(1/i!, i=0..n). Plug that and the values for R and t into the formula given by S.  I presume you can do that in Excel.

Thanks for adding information about the range of R=0.0..1.0 to your post.

It seems to me that a series approximation fits the MTBF well for R in that range, with t>0, n::posint, etc.

The approximating formula is given by S below. You indicated that you could handle a finite sum (which appears in S).

Let me know, if I've misunderstood. (I discounted this earlier, since I didn't know R and the series approach breaks down for certain t and n when R>1.)

The plot and the Explore are meant to illustrate that ee, eeG, and S agree quite well in the given ranges of the parameters.

> 

restart:

> 

ee := solve(R = exp(t/MTBF) * (t/MTBF) * Sum(1/(i!), i=0..n),MTBF);

t/LambertW(R/(Sum(1/factorial(i), i = 0 .. n)))

> 

eeG := solve(R = exp(t/MTBF) * (t/MTBF) * sum(1/(i!), i=0..n),MTBF);

t/LambertW(exp(-1)*R*GAMMA(n+1)/GAMMA(n+1, 1))

> 

S := convert(series(ee,R=0,6),polynom);

(Sum(1/factorial(i), i = 0 .. n))*t/R+t-(1/2)*t*R/(Sum(1/factorial(i), i = 0 .. n))+(2/3)*t*R^2/(Sum(1/factorial(i), i = 0 .. n))^2-(9/8)*t*R^3/(Sum(1/factorial(i), i = 0 .. n))^3

> 

eplot:=proc(T,N)
   plot(eval([ee, S, eeG],[t=T, n=N]),
        R=0..1,
        style=[line,point,point],
        symbol=[solidcircle,diagonalcross],
        symbolsize=[8,16],
        color=[green,black,red],
        numpoints=20);
end proc:

> 

eplot(33.0, 5);

> 

#Explore(eplot(t,n), parameters=[t=0..100, n=1..10]);

> 

 


Download MTBF1.mw

@Markiyan Hirnyk He didn't ask for a closed form. He asked about something he could use in Excel.

Note that the latter part of my Answer (not Comment) was about what was giving him grief, not what I was suggesting to do. And the first part got rid of the GAMMA calls he seemed to not want. That left the LambertW. So in my followup Comment I discussed obtaining an approximating expression.

Now, obtaining a black box approximating mechanism that allows for arbitrary float R and posint n, to work in Excel, is more work...

If you know particular values for n and t as well as the range for R then you can use Maple to construct H = P(R)/Q(R) which approximates your expression quite well, where P(R) and Q(R) are polynomials in R with float coefficients.

For example (there are other similar ways... you can even get an estimate of the error bound).

> 

restart:

> 

ee := solve(R = exp(t/MTBF) * (t/MTBF) * Sum(1/(i!), i=0..n),MTBF);

t/LambertW(R/(Sum(1/factorial(i), i = 0 .. n)))

> 

P := plot(value(eval(ee,[n=15,t=0.3])),R=0..3,color=green):

> 

H := eval(numapprox:-chebpade(value(eval(ee,[n=15,t=0.3])),R=0.1..3,[4,4]),
     T = orthopoly[T]);

(-.1046598996+.3979979186*R+.2094792186*((20/29)*R-31/29)^2+0.2631635411e-1*((20/29)*R-31/29)^3+0.7344468442e-3*((20/29)*R-31/29)^4)/(-.6116268169+.8210912092*R+.6724478367*((20/29)*R-31/29)^2+.1360729330*((20/29)*R-31/29)^3+0.7230731934e-2*((20/29)*R-31/29)^4)

> 

PH := plot(H, R=0..3, color=red, style=point, numpoints=20):

> 

plots:-display(P, PH, view=-10..10);

> 

 

 

Download LW2.mw

 

@tomleslie Saving to .m format was not always discouraged. It's a convenient way to save results of time consuming computations. It's easier to do than to store in an .mla archive, especially if there are several such results to handle separately.

One major reason for its being discouraged, AFAIK, is that it cannot handle everything. It can't handle modules and records in general. Localness is a problem. For a many instances that is not a problem, however.

Some of the best resources on basic and introductory Maple programming are older texts and web resources, some of which use this functionality as a stock tool.

So it's not so surprising that people would utilize the functionality.

@tomleslie The order of terms in SUM DAG assigned to name p are at issue here. It may be that conjoining the restart and the initial assignment to p involves a SUM with the terms stored in a different order than otherwise. But that is not the only way to get a SUM which exhibits the problem.

For example (and this is just showing a way to force the problem -- in general we would not know how p was formed and by what commands),


> 

restart;

> 

p:=x^2*y-2*y*z+3*x^2+2*y-z:
sort(p,order=plex(x,y,z), ascending);

> 

cl:=[coeffs(p, [x,y,z])]:

> 

[seq(`if`(cl[j]>0,seq(op(j,p)/cl[j], i=1..cl[j]),NULL),j=1..numelems(cl))];

                                             2    2  
                       -z + 2 y - 2 y z + 3 x  + x  y
               [  1      1            1  2    1  2    1  2  ]
               [- - z, - - z, -2 y z, - x  y, - x  y, - x  y]
               [  2      2            3       3       3     ]

> 

restart;

> 

p:=x^2*y-2*y*z+3*x^2+2*y-z:
sort(p,order=plex(x,y,z), descending);

> 

cl:=[coeffs(p, [x,y,z])]:

> 

[seq(`if`(cl[j]>0,seq(op(j,p)/cl[j], i=1..cl[j]),NULL),j=1..numelems(cl))];

                         2        2                  
                        x  y + 3 x  - 2 y z + 2 y - z
                [1  2    1  2              1      1      1  ]
                [- x  y, - x  y, -2 y z, - - z, - - z, - - z]
                [2       2                 3      3      3  ]

> 

 


Download sumdagf.mw

As for the question of restart and additional commands in the same execution group, I have observed the problem occuring for commands which are intercepted by the GUI. By this I mean commands which get executed by the Java Standard GUI (!) rather than the Maple kernel (aka mserver, aka engine). In particular the interface command fits in this problematic class, but I believe that there are others. (The difference can be established by running particular code that calls the intercepted commands at the top level in the GUI versus inside a procedure executed in the GUI.) For example, an interface call following a restart, in the same execution group, can get ignored by the GUI. So, sure, using a separate execution group for restart, alone, is the right way to go.

The main point is that the terms in a polynomial such as p may be sorted internally in different ways.

And, with a local X...


> 

restart:

> 

aliasedlatex:=proc(e)

> 

  local lookup;

> 

  lookup:=op(eval(alias:-ContentToGlobal)):

> 

  :-latex(subs(lookup,e));

> 

  NULL;

> 

end proc:

> 

local X;

> 

alias(X=:-X(a,b,c)):

> 

test:=diff(:-X(a,b,c),a);

diff(X(a, b, c), a)

> 

latex(test);

{\frac {\partial }{\partial a}}X \left( a,b,c \right)

> 

 

> 

aliasedlatex(test);

{\frac {\rm d}{{\rm d}a}}X

> 

 


Download aliasedlatexlocal.mw

Hmm, I guess that had better be subs instead of eval, or else derivatives become 0.


> 

restart:

> 

aliasedlatex:=proc(e)

> 

  local lookup;

> 

  lookup:=op(eval(alias:-ContentToGlobal)):

> 

  :-latex(subs(lookup,e));

> 

  NULL;

> 

end proc:

> 

alias(Y=X(a,b,c)):

> 

test:=diff(X(a,b,c),a);

diff(Y, a)

> 

latex(test);

{\frac {\partial }{\partial a}}X \left( a,b,c \right)

> 

 

> 

aliasedlatex(test);

{\frac {\rm d}{{\rm d}a}}Y

> 

 


Download aliasedlatexsubs.mw

@Carl Love I did it that way so that the name UpdatingRead wouldn't itself appear in the Variable Manager, if the code was just pasted into a worksheet. It wasn't the only way to get that effect, but served that purpose.

Of course, one could instead savelib just the assigned UpdatingRead procedure to a .mla archive located in libname in future sessions.

I wanted the OP to see the addition of his .m file's missing names to the Variable Manager, using the posted Answer code in the simplest way, without the effect of the Variable Manager being cluttered by the name UpDatingRead itself.

Who knows... maybe someone will fix assign so that it too updates the Variable Manager. In which case the behaviour would be the same either way. It was intended only as the most minor aspect, and is not a big deal.

First 349 350 351 352 353 354 355 Last Page 351 of 613