4 years, 71 days

## Hi,  Have you try to use the geomet...

Hi,
Have you try to use the geometry package?
Here are some of its capabilities that could interest you.

 > restart:
 > with(geometry): with(RealDomain):
 > local D, O:
 > _EnvHorizontalName := x: _EnvVerticalName := y: point(O, [0, 0]);
 (1)
 > # D is assumed neither horizontal nor vertical line(D, a*x+b*y+c) assuming a^2 + b^2 > 0, a<>0, b<>0: PerpendicularLine(Perp, O, D): projection(H, O, D): coordinates(H);
 (2)
 > # D is assumed vertical line(D, b*y+c) assuming b<>0, b^2 > 0: PerpendicularLine(Perp, O, D): projection(H, O, D): coordinates(H);
 (3)
 > # D is assumed horizontal line(D, a*x+c) assuming a<>0, a^2 > 0: PerpendicularLine(Perp, O, D): projection(H, O, D): coordinates(H);
 (4)
 >

## There are probably a lot of ways to that...

There are probably a lot of ways to do that.
Here is one of them
(the set of points I construct are in some sense the "shortest" for adding them any other point from the initial list obviously creates a new set of points whose sum id larger than the target sum)

 > restart:
 > randomize():
 > M    := 10.: roll := rand(0. .. M): N    := 10: L    := [seq(roll(), k=1..N)]
 (1)
 > ROLL := rand(0..N*M): S    := ROLL();  # target sum
 (2)
 > # First way c := Statistics:-CumulativeSum(L): if c[-1] < S then   printf("The sum of all the numbers (%a) is less than rge desired sum (%a)\n", c[-1], S) else   select[flatten](<, c, S);   selected_numbers := L[1..numelems(%)+1];   # verify   is(add(selected_numbers) > S) end if;
 (3)
 > # Repeat this many (R) times. R := 10: for r from 1 to R do   rL := combinat:-randperm(L):   c := Statistics:-CumulativeSum(rL):   if c[-1] < S then     printf("The sum of all the numbers (%a) is less than rge desired sum (%a)\n", c[-1], S)   else     select[flatten](<, c, S);     selected_numbers := rL[1..numelems(%)+1];     printf("%a\n", selected_numbers);   end if; end do:
 [2.715869968, 8.629534219] [4.004192509, 7.267252468] [8.629534219] [3.829591035, 3.288246716, 8.629534219] [2.715869968, 3.829591035, 7.267252468] [8.629534219] [7.550798661, 7.992442854] [3.829591035, 7.267252468] [7.267252468, 7.992442854] [8.629534219]
 >
 >
 >
 >
 >
 > # select the smallest number in wich is larger than 3.14 L[ListTools:-BinaryPlace(L, 3.14)+1]; min(select[flatten](>, L, 3.14))
 (4)
 > # select the smallest number in wich is larger or equal than 4 min(select[flatten](>, L, 4)); min(select[flatten](>=, L, 4));
 (5)
 > # all the points in L that are larger or equal than 4 LL := select[flatten](>=, L, 4)
 (6)
 > # randomly select some of them, let's say 3 of them combinat:-randperm(LL)[1..3]
 (7)
 >
 >
 >

Without any constraints on the selcted numbers, all the solutions are equivalent.
But maybe you are looking for the selected numbers whose sum is the closest to the target sum?
Or the minimum set of numbers whose sum is larger than this target sum?

## interface(imaginaryunit=i)...

interface(imaginaryunit=i)

## A minimal answer (LinearFit can return a...

A minimal answer (LinearFit can return a lot of informations, please look to the corresponding help page).

## Probably the shortest coding (note that ...

Probably the shortest coding (note that prime number 2 is congruent to 2, so there also exists a list L[2] with only one member)

Statistics:-Tally(mod(select(isprime, L), 8))

If you do not want to compute the number of elements L[2] has (which is obviously 1 whatever the length of L), the simplest thing do do is to begin the construction from the 3rd element of L (the first (1) is not prime, and the second (2), is the prime you don't want to count)

Statistics:-Tally(mod(select(isprime, L[3..-1]), 8))

## @minhhieuh2003  I have no cure to ...

@minhhieuh2003

I have no cure to that, only an explanation.
If you type whattype(1/x) you will get ^ meaning 1/x is not interpreted as a fraction but as somthing (x) raised to some power (-1).
This is confirmed by type(1/x, fraction) whose output is  false.
(but type(2/3, fraction)returns  true).
Then the latex command probably uses the representation of 1/x to do the LaTeX translation, and this representation is of power type and not of fraction type.
More precisely I think latex uses the representation produced by the command dismantle :
dismantle(1/x)
PROD(3)
NAME(4): x
INTNEG(2): -1

You see here that 1/x is some name raised to an integer power equal to -1. This is consistent with the outputs of whattype(1/x) and type(1/x, fraction).

Look now what dismantle(2/3) returns
dismantle(2/3)
RATIONAL(3): 2/3
INTPOS(2): 2
INTPOS(2): 3

To force latex to return something like \frac{1}{x} you could think to write your own procedure, for instance
latex/frac := proc()
cat(\\frac{, latex/print(args[1]), }{, latex/print(args[2]), } )
end proc;

See what the result will be
printf("%s", latex/frac(1, x^2+2))

But the harder problem will be to force maple to interpret  1/expression as a fraction and not as this expression to the power -1 (more generally to interpret expression_1/expression_2 as a fraction).
And this one I'm not sure it can be solved ???

As a last resort, you can always write your own Maple --> LateX converter.
You fill find in the attached file ad hoc a snippet of an ad hoc LaTeX translator

 > restart
 > # Ultimately you can do that by hand: cat(\\int{2}{3}\\frac{1}{, latex/print(x^2+2), }=, latex/print(eval(parse(expr))) ): printf("%s", %);
 \int{2}{3}\frac{1}{{x}^{2}+2}={\it expr}
 > # But it would be more generic to write your own procedure
 > latex/frac := proc()   if patmatch(args[1], (a::anything)/(b::anything), 's' ) then     if rhs(s[2]) <> 1 then       cat(\\frac{, latex/print(rhs(s[1])), }{, latex/print(rhs(s[2])), } )     else       cat(latex/print(rhs(s[1])))     end if:   end if: end proc:
 > printf("%s", latex/frac(1/(x^2+2)))
 \frac{1}{{x}^{2}+2}
 > printf("%s", latex/frac(x*(x^2+2)))
 x \left( {x}^{2}+2 \right)

 > LateX/Int := proc(expr)   local L, i, v, lob, upb:   L := [op(0..-1, expr)]:   if L[1] <> Int then error "the expression is not of type Int" end if:   if patmatch(L[2], (a::anything)/(b::anything), 's' ) then     if rhs(s[2]) <> 1 then       i := cat(\\frac{, latex/print(rhs(s[1])), }{, latex/print(rhs(s[2])), } )     else       i := cat(latex/print(rhs(s[1])))     end if:   end if:   v := lhs(L[3]):   if type(L[3], =) then     lob := op(1, rhs(L[3])):     upb := op(2, rhs(L[3])):     cat(\\int_{, latex/print(lob), }^{, latex/print(upb), }\\!, i, \,{\\rm d}, latex/print(v))   else     cat(\\int_{, latex/print(eval(lob)), }^{, latex/print(upb), }\\!, i, \,{\\rm d}, latex/print(v))   end if: end proc:
 > latex(Int(x, x=0..1))
 \int_{0}^{1}\!x\,{\rm d}x
 > printf("%s", LateX/Int(Int(x, x=0..1)))
 \int_{0}^{1}\!x,{\rm d}x
 > printf("%s", LateX/Int(Int(1/(x^2+2), x=0..1)))
 \int_{0}^{1}\!\frac{1}{{x}^{2}+2},{\rm d}x
 >

## Hi, I guess that R1 and R2 hav...

Hi,

I guess that R1 and R2 have bounded supports S1 and S2 (if not either the min or the max or both of them is infinite).
I also admit that the function f : (R1, R2) ---> X is everywhere defined over S1xS2 (wich is not the case if f(R1,R2)=R1/R2 and S2 contains {0}).

So, if I understand correctly your question,  there is no need to use random variables to find the min and the max of X.

The case of "nom" (I guess "nominal") is more subtle. But if you do not rely "nominal" to some statististics of R1 and R2 ("nominal" is just some specific value, not a mean, median, mode, ...) then Tolerances is stiil the paxkage to use.

If "nominal" repesent mean values (for instance), the "nominal" value of X can be easily obtained by using the package ScientificErrorAnalysis.
Feel free to tell me if this didn't help

## If you want to represent a univariate po...

If you want to represent a univariate polynomial in some orthogonal polynomial expansion, this might interest you.

PS: the last command InsertContent(Worksheet(Group(Input( A ))));  can't be displayed here, just run the code to visualize it.

 > restart:
 > interface(version);
 (1)
 > with(DocumentTools): with(DocumentTools:-Layout):
 > OP := with(orthopoly)
 (2)
 > F := proc(P, x, B)   local d, C, Q, symb:   if _npassed = 4 and _passed[3] <> G then     error cat("A fourth argument (", _passed[4], ") is provided but the orth. poly is not of type G")   end if;   if _npassed = 3 and _passed[3] = G then     error cat("Using type G orth. poly. needs to pass F a fourth argument, see orthopoly[G] help page")   end if;   d    := degree(P, x):   symb := convert(cat("#mrow(mo(", B, "))"), name);   if _passed[3] <> G then     Q := add(a[n]*B(n, x), n=0..d):     C := op(solve( [ coeffs( collect(expand(P-Q), x), x) ], [ seq(a[n], n=0..d) ] )):     return add(rhs~(C) *~ [ seq(symb(n, x), n=0..d) ])   else     Q := add(a[n]*B(n, _passed[4], x), n=0..d):     C := op(solve( [ coeffs( collect(expand(P-Q), x), x) ], [ seq(a[n], n=0..d) ] )):     return add(rhs~(C) *~ [ seq(symb(n, _passed[4], x), n=0..d) ])   end if: end proc:
 > # Laguerre representation of polynom Pol # (watchout : do not name P this polunomial to avoid conflicts with orthopoly P) # note the character "L" that appears here is not the "L" which represents LaguerreL polynomials Pol := randpoly(x, dense, degree = 4); B   := L: pol := F(Pol, x, B); pol := F(Pol, x, B, 1); print(); B   := G: pol := F(Pol, x, B); pol := F(Pol, x, B, 1);
 (3)

 > # Extract the symbol used and replace it by B and verify the result is Pol symb := op(0, indets(pol, function)[1]); eval(pol, symb=B); %-Pol
 (4)
 > # Several orthogonal polynomials representations # Watchout: Gegenbauer polynomials ar not handled N := numelems(OP): M := Matrix(N+1, 2): M[1, 1] := 'canonical': M[1, 2] := Pol: k := 2: for B in OP do   M[k, 1] := B:   M[k, 2] := if(B <> G, F(Pol, x, B), F(Pol, x, B, 1)); # for instance   k := k+1: end do: A := Table(             seq(Column(), k=1..12), widthmode=percentage, width=60, # width has to be adjusted for larger expressions             seq(                  Row(                       Cell( Textfield( style=TwoDimOutput, Equation(M[k,1]) ), columnspan=2),                       Cell( Textfield( style=TwoDimOutput, Equation(M[k, 2]) ), columnspan=10)                  ),                  k=1..N+1             )      ): InsertContent(Worksheet(Group(Input( A ))));
 >

## You will find below how to modify the st...

You will find below how to modify the structure plotted by DrawGraph in order that the thickness of the edges are proportional to their weights.
The code is not robust because it doesn't gandle situations where the weights are not integers nor situations where the range of the weight is very large (let's say 1..100 for instance).
I tried to be pedagocic by diplaying intermediate steps.

PS: I used MAPLE 2015... maybe more recent version have embedded features to do all thus stuff

 > restart:
 > interface(version);
 (1)
 > with(GraphTheory):
 > G := Graph({[{1,2},2],[{2,3},1],[{1,3},3]});
 (2)
 > p := DrawGraph(G): plots:-display(p);
 > # What does p contain? d := [op(p)]: print~(d):
 (3)
 > nv := numelems(Vertices(G)); ne := numelems(Edges(G));
 (4)
 > # d[1]                   draws the nv yellow squares that represent the vertices # d[2]...d[nv+1]         draw the labels of the vertices # d[nv+2]..d[nv+2+ne-1]  draw the ne edges # ... # # q contains the elements of d that we won't change # r contains the elements of d that we are going to change q := d[[$1..nv+1,$nv+2+ne..numelems(d)]]: print~(q): print(): r := d[[$nv+2..nv+2+ne-1]]: print~(r):  (5)  > # verification plots:-display(r);  > # get tertex positions v := GetVertexPositions(G);  (6)  > # change the default thickness by the weight of the edge(assuming it is a positive number) W := WeightMatrix(G); S := NULL: for s in r do __edge := op(1, s): # the edge "s" __from_to := map(ListTools:-Search, __edge, v): # starts at "from" and ends at "to" __thickness := W[op(__from_to)]: S := S, subs(THICKNESS(2) = THICKNESS(__thickness), s) end do: PLOT(S);  > # plot the sequence q, S PLOT(q[], S)  > Download WeightedEdges.mw ## To complete Kitonum's and Rouben'... To complete Kitonum's and Rouben's replies, and if you have Maple 2018 or higher, you can also use the Kriging method (from memory look to the CurveFitting package ... If I'm mistaken please corrrect me). Less immediate if you do not know the basis of Kriging, but this will give you a more flexible way to obtain a function which interpolates your unknown function from a set of X-Y couples. For I only have Maple 2015 right now, I've written an extremely simple procedure to do "simple Kriging". Here is a few examples of interpolators you can build (the X-Y couples come from your plot)? They differ by the value of a scalar parameter which controls the smoothness of the interpolation. ## @tayyild Here is a solution which w... @tayyild Here is a solution which works for 2 or more polynomials of arbitrary number of monomials. The procedure needs two lists P and V of equal lengths: • P[n] denotes the number of monomials of polynom n • V[n] denotes the symbol used to represent polynom n Your first example is coded P := [2, 2], V=[x, y] and your second P := [3, 3], V=[x, y]. A_general_solution.mw ## Hi, Maybe you could begin by look... Hi, Maybe you could begin by looking at the functions these 3 different packages provide (the texts come from a copy-paste of the help pages). You will probably find a lot of useful informations. • The DynamicSystems package is a collection of procedures for creating, manipulating, simulating, and plotting linear systems models. In particular, • The TransferFunction command creates a transfer function (TF) system object. The frequency-domain behavior of the object is modeled by rational functions (ratpoly) corresponding to transfer functions in the frequency domain. • The ExcelTools package is a collection of commands that allow access to data stored in Microsoft Excel format (XLSX and XLS). • Mayne this one can also be usefull: The SignalProcessing package provides commands for manipulating signals. Specifically, these commands work on samples of signals stored in Vectors with datatype float[8] or complex[8]. ## Maybe you could use FileTools[Binar... Maybe you could use FileTools[Binary][CountBytes](file) to check if the number of bytes has changed from the previous checking. ## Hi, Weighted Least Squares are defi... Hi, Weighted Least Squares are defined by (in your notation) wi*(yi_exp-yi_calc)^2. So Maple should use this weighting... It's easy to check what Maple realy does if you compute the regression coefficients by hand. Download Weighed_Least_Squares.mw The answer is : Yes, Maple uses the formula wi*(yi_exp-yi_calc)^2 ## I understand that y is a function o... I understand that y is a function of t parameterized by K and M and I guess your experimental data are observations of Y for some values of t. Am I right? If I am, then you will find a few elements in the attached file that could help you. In a few words: • If the integral of f*g*p has a closed form expression (case 1 in the attached file), then you can (probably alwways) use NonlinearFit. • But given the error message you got, I assume it's not the case. Case 2 in the attached file mimics that situation where you cannot use NonlinearFit • I propose a workaround based on the minimization of an objective function defined as the sum of squares between y(t[n], K, M) and the observations of Y at "times" t[n]. In all the examples I generate pseudo observations this way: 1. I fix K and M to a priori values (here 0.1 and 1) 2. I compute y(t, K, M) for integer values of t from 0 to 10 included 3. So the solution returned by any minimization algorithm must be K=0.1 and M=1 The two-steps definition of Y is not necessary: here I first define y(t) in a general way, next I specify Y by giving specific forms to f, g and p. You can "muse" by changing these expressions to see what happens. Note that, for your real problem, the numerical integration method I use (_Qquad, see help(Int[evalf]) ) may not be the correct one to use. Do not hesitate to contact me for more information.  > restart: Case 1: the product f.g.p is integrable  > y := t -> M*int(f(x)*g(x, M)*p(x, t, M,K), x=a..b)  (1)  > # Example: # an arbitrary choice of f, g and p Y := eval(y(t), [f=(x->x+1), g=((x,M)->x*M), p=((x,t,M,K)->exp(x*M+t*K))])  (2)  > # Example continued: # Taking a=0 and b=1, and assuming K=1/10 and M =1, # generate 11 observations of Y for values of t from 0 to 10 by 1 Y__obs := evalf( [ seq(eval(Y, [M=1, K=1/10, a=0, b=1]), t =0..10) ] )  (3)  > # Example still continues: # How can we assess K and M by fitting the "model" Y on the observations? Yab := eval(Y, [a=0, b=1]): Statistics:-NonlinearFit(Yab, Vector([$0..10]), Vector(Y__obs), t, output=parametervalues)
 (4)

 > restart:

Case 2: the product f.g.p is not integrable

The error Maple returns is the one you mention in your post

 > y := t -> M*int(f(x)*g(x, M)*p(x, t, M,K), x=a..b)
 (5)
 > # Example: # an arbitrary choice of f, g and p Y := eval(y(t), [f=(x->cos(x)), g=((x,M)->x*M), p=((x,t,M,K)->exp(x^3*M+t*K))])
 (6)
 > # Example continued: # Taking a=0 and b=1, and assuming K=1/10 and M =1, # generate 11 observations of Y for values of t from 0 to 10 by 1 T__obs := [\$0..10]: Y__obs := evalf( [ seq(eval(Y, [M=1, K=1/10, a=0, b=1]), t in T__obs) ] )
 (7)
 > # Example still continues: # How can we assess K and M by fitting the "model" Y on the observations? Yab := eval(Y, [a=0, b=1]); Statistics:-NonlinearFit(Yab, Vector(T__obs), Vector(Y__obs), t, output=parametervalues)

a workaround on the same example

 > y := (t, K, M) ->           evalf(             M*Int(                    eval( f(x)*g(x, M)*p(x, t, M,K), [f=(x->cos(x)), g=((x,M)->x*M), p=((x,t,M,K)->exp(x^3*M+t*K))] ),                    x  = eval(a..b, [a=0, b=1]),                    method = _Gquad                  )           ): # examples : y(t, K, M); y(1, 1, 1)
 (8)
 > # Define the "objective function" as the residual sum of squares obj := proc(K, M) add( ( y(T__obs[n], K, M) - Y__obs[n] )^2, n=1..numelems(T__obs) ) end proc:
 > # Use (for instance) Optimization:-NLPSolve to find the minimum of # the objective function. # # Watchout: the ranges of K and M are of major importance. Optimization:-NLPSolve(obj, 0.01..1, 0.01..2, maximize=false)
 (9)
 >

 1 2 3 4 5 6 7 Last Page 2 of 13
﻿