4 years, 1 days

## Here is an example (data XY come from th...

Here is an example (data XY come from the CurveFitting:-Spline help page)
The trap would be to search the extrema of each pice of the global function without accounting for the interval this piece is defined on. Another trap would be to search for extrema outsise the interval defined by the data.

 > restart:
 > with(CurveFitting):
 > XY := [[0,0],[1,1],[2,4],[3,3]]; S := Spline([[0,0],[1,1],[2,4],[3,3]], v);  (1)
 > # ranges bounds := min(op~(1, XY)), seq(rhs(op(k, S)), k in [seq(1..nops(S)-1, 2)]), max(op~(1, XY)); ranges := seq(bounds[k]..bounds[k+1], k=1..numelems([bounds])-1)  (2)
 > # 1st derivative of the S dS := seq(diff(op(k, S), v), k in [seq(2..nops(S), 2)]), diff(op(-1, S), v); (3)
 > # extrema sol := seq([fsolve(dS[k], v=ranges[k])], k=1..numelems([dS])) (4)
 > # reconstruction as a piecewise solution piecewise(seq(op([v >= op(1, ranges[k]) and v < op(2, ranges[k]), sol[k]]), k=1..numelems([sol]))) (5)
 >

## @JAMET  @KitonumHi JAMET, I do...

Hi JAMET,

I don't know if the solution Kitonum has provided suits you (I understood you were looking for something more formal?).
If I'm mistaken forget what comes below, otherwise this worksheet might interest you.
From a line L defined by its cartesian equation it contains the step by step procedure to:

1. construct the equation of L in the complex plane
2. construct the equation of the line orthogonal to L and which passes through (0, 0)
3. construct the expression of the intersection of these two lines

All of this is done formally, two examples follow with drawings

 > restart:
 > alias(conj = conjugate):
 > assumptions := (a::real, b::real, c::real, x::real, y::real) (1)
 > # Cartesian equation of line L L := a*x + b*y - c (2)
 > # let Z a complex number rel_1 := Z = x + I*y (3)
 > # let Z bar its conjugate rel_2 := #mrow(mover(mo(Z),mo("̅"))) = eval(conj(Z), rel_1) assuming assumptions (4)
 > # explain x and y in terms of Z and Z bar interface(warnlevel=0): rel_3 := op( solve([rel_1, rel_2], [x, y]) ) (5)
 > # rewrite L by using the above equalities eval(L, rel_3); (6)
 > # take the numerator of this expression numer(%); (7)
 > # collect the result according to Z and Z bar #mrow(mo("ℒ"))  := collect(%, [Z, #mrow(mover(mo(Z),mo("̅")))]) (8)
 > # define the complex number v from a and b rel_4 := v = a+I*b (9)
 > # let v bar its conjugate rel_5 := #mrow(mover(mo(v),mo("̅"))) = eval(conj(v), rel_4)  assuming assumptions; (10)
 > # reverse rel_4 and rel_5 rel_6 := (rhs=~lhs)~([rel_4, rel_5]) (11)
 > # here is the equation of L in the complex plane #mrow(mo("ℒ")) := eval(#mrow(mo("ℒ")), rel_6) (12)
 > # find the complex equation of the line orthogonal to L and passing through the origin [0, 0] # # firstly define w as a rotation by Pi/2 of the vector whose affix is [a, b] in the complex plane rel_7 := w = v*I (13)
 > # let w bar its conjugate rel_8 := #mrow(mover(mo(w),mo("̅"))) = eval(conj(w), rel_7); rel_8 := eval(rel_8, conj(v) = #mrow(mover(mo(v),mo("̅"))));  (14)
 > # here is the equation of the line orthogonal to L, and which passes through the origin #mrow(mo("ℋ")) := eval(                                 #mrow(mo("ℒ")),                                 [                                   v=w,                                   #mrow(mover(mo(v),mo("̅"))) = #mrow(mover(mo(w),mo("̅"))),                                   c=0                                 ]                               ) (15)
 > # where do lines L and H intersect ? # # let's form this system in Z and Z bar (brute force) sys := [ #mrow(mo("ℒ")) = 0, eval(#mrow(mo("ℋ")), [rel_7, rel_8]) = 0 ]: print~(sys):  (16)
 > # where do lines L and H intersect ? sol := op( solve( sys, [ Z, #mrow(mover(mo(Z),mo("̅"))) ] ) ) (17)
 > # use the expression of v to explicit the solution (obviously Z and Z bar are conjugate) sol := eval(sol, [rel_4, rel_5]); (18)
 > # transform the solution into a prettier form sol := lhs~(sol) =~ numer~(rhs~(sol)) *~ conj~(denom~(rhs~(sol)))                     /~                     expand~(denom~(rhs~(sol)) *~ conj~(denom~(rhs~(sol))) )  assuming assumptions (19)
 > # this complex number -represents the affix of the intersection point of the two lines #mrow(mo("ℤ")) := simplify(eval(Z, sol));  # asuming a^2+b^2 <> 0 (20)
 > # example data := [a=3, b=-2, c=1, x=X, y=Y]: with(plots): f := eval(a*X + b*Y - c, data); #mrow(msub(mo(f),mo("⊥"))) := simplify(                                         eval(                                           eval(                                             eval(#mrow(mo("ℋ")), [rel_1, rel_2, rel_7, rel_8]),                                             [rel_4, rel_5]                                           ),                                           data                                         )                                       ); __Z := eval(#mrow(mo("ℤ")), data); display(   implicitplot(f, X=-1..1, Y=-1..1, color=blue),   implicitplot(#mrow(msub(mo(f),mo("⊥"))), X=-1..1, Y=-1..1, color=red),   pointplot([[Re(__Z), Im(__Z)]], symbol=circle, symbolsize=20),   gridlines=true,   scaling=constrained );    > # just another example data := [a=0, b=-3, c=-2, x=X, y=Y]: with(plots): f := eval(a*X + b*Y - c, data); #mrow(msub(mo(f),mo("⊥"))) := simplify(                                         eval(                                           eval(                                             eval(#mrow(mo("ℋ")), [rel_1, rel_2, rel_7, rel_8]),                                             [rel_4, rel_5]                                           ),                                           data                                         )                                       ); __Z := eval(#mrow(mo("ℤ")), data); display(   implicitplot(f, X=-1..1, Y=-1..1, color=blue),   implicitplot(#mrow(msub(mo(f),mo("⊥"))), X=-1..1, Y=-1..1, color=red),   pointplot([[Re(__Z), Im(__Z)]], symbol=circle, symbolsize=20),   gridlines=true,   scaling=constrained );    >

## 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 with only one member)

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

If you do not want to compute the number of elements L 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), }{, latex/print(args), } )
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, (a::anything)/(b::anything), 's' ) then     if rhs(s) <> 1 then       cat(\\frac{, latex/print(rhs(s)), }{, latex/print(rhs(s)), } )     else       cat(latex/print(rhs(s)))     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 <> Int then error "the expression is not of type Int" end if:   if patmatch(L, (a::anything)/(b::anything), 's' ) then     if rhs(s) <> 1 then       i := cat(\\frac{, latex/print(rhs(s)), }{, latex/print(rhs(s)), } )     else       i := cat(latex/print(rhs(s)))     end if:   end if:   v := lhs(L):   if type(L, =) then     lob := op(1, rhs(L)):     upb := op(2, rhs(L)):     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 <> G then     error cat("A fourth argument (", _passed, ") is provided but the orth. poly is not of type G")   end if;   if _npassed = 3 and _passed = 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 <> 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, 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, 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)); 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                   draws the nv yellow squares that represent the vertices # d...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) >

## 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 or complex.

## 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.

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