8 years, 71 days

## MaplePrimes Activity

### These are answers submitted by sand15

By the way, I guees the integration range in the definition of M could be x=a..Q instead of x=0..Q ?

Could it be you are looking for that?

restart :
with(Statistics):

z := proc(S, c0, cs, F)
local a, b, M, N, ECost, DCost, f:
f := unapply(F, x):
a:=min(S):
b:=max(s)
M := int((Q-x)*f(x), x=a..Q):
N := int((Q-x)*f(x), x=Q..b):
ECost:=c0*M+cs*N:
DCost := diff(ECost, Q):
return fsolve(DCost=0, Q)
end proc:

Sam := Sample(Uniform(10, 10), 10):

# usage

z(Sam, 20, 25, 1);   # the last argument means “the function f(x) is a constant”
z(Sam, 20, 25, Pi);   # same result whatever the constant is
z(Sam, 20, 25, x);   # f(x) = x
z(Sam, 20, 25, exp(x));   # f(x) = exp(x)

# Naive coding

R := 1000:

AllQs := Vector[row](R):
for r from 1 to R do
Sam := Sample(Uniform(10, 10), 10):
AllQs[r] := z(Sam, 20, 25, 1);
end do:

# more elaborate coding

Sam := Sample(Uniform(10, 10), [R, 10]):   # a  matrix of R samples

AllQs := map(r -> z( entries(Sam[r, ..], nolist), 20, 25, 1);

## Have you try thisrestart:roll := rand(0....

Have you try this

restart:
roll := rand(0.0 .. 1.0):
N := 100:  # for example
s := [ seq(roll(), k=1..N) ]:
RandPerm := sort(s, output=permutation);

BTW : a random permutation of {1, 2, ...N} will ALWAYS return {1, 2, ..., N}. You must work with "ordered" objects such as lists, vectors, ..., not with sets

## Correct values...

Add these two lines to your code to obtain the correct estimators.

Unweighted_X_Sample := [ seq( X[n]\$(round(Y[n]), n=1..numelems(X) ) ]:
DataSummary(X);

PS: works here because the weights are integers represented as floats.
In more general case (real weights) the procedure is easily generalizable (a very classical situation encountered by people who use MCMC methods for instance)

## Hi,   restart: X := [1, 2, 3, 4]...

Hi,

restart:

X := [1, 2, 3, 4];

babyGrid := proc()
[ Grid:-MyNode(), X]
end proc;

Grid:-Launch(babyGrid, imports=['X'])

## @LichengZhang   Sorry, I did not ...

@LichengZhang

Sorry, I did not realize you wanted the TOTAL number of cycles.

As far as I know there is no function in Maple to do this, but you can obtain all the cycles by just "merging" the cycles of the cycle basis.
In a few words, CycleBasis returns a list of cycles, each of them being a list of vertices.
From this list you construct the set of edges that form the graph cycle.
Once done,  "merging in an adhoc way" some of  these sets will produce a new set that corresponds to a new cycle.

I think the code below returns the good result but I have no time to vericy this on a lot of graphs.

(if it's not the case I will correct it from my login  @mmcdara)

 >
 > restart:
 > with(GraphTheory): with(SpecialGraphs):
 > G := OctahedronGraph(); DrawGraph(G); Cycles := CycleBasis(G); N := numelems(Cycles);
 (1)
 > # close the list of vertices by adding the first vertex to its right for n from 1 to N do    C||n := [Cycles[n][], Cycles[n][1]]; end do;
 (2)
 > # Create the sets of edges for each cycle for n from 1 to N do    S||n := map(m -> {(C||n)[m], (C||n)[m+1]}, {\$1..numelems(C||n)-1}); end do;
 (3)
 > S0 := {seq(S||n, n=1..N)}
 (4)
 > with(combinat, powerset):
 > PS := powerset(S0): NS := numelems(PS);
 (5)
 > # Do some surgery while avoiding the empty set and the basis sets AllCycles := NULL: for ns from N+2 to NS do    AllCycles := AllCycles, `union`(seq(PS[ns][k], k=1..nops(PS[ns]))) minus  `intersect`(seq(PS[ns][k], k=1..nops(PS[ns]))) end do: AllCycles := {AllCycles}: NAC := numelems(AllCycles);
 (6)
 > {seq(`union`(op~(AllCycles[n])), n=1..NAC)} union {convert~(Cycles, set)[]}; TotalNumberOfCycles := numelems(%);
 (7)
 >

## The "median" is either the mid...

The "median" is either the midpoint of a segment or either a statistical quantity. As you seem to be interested in computing the "median" for an arbitrary number of points, I guess that you refer to the statistical quantity.

In this, if you do not already know this, you will find in the "Statistics" package two procedures named Median and Mean that you can assemble in a single procedure

medianmean := proc(x::list)
uses Statistics:
return [x, Median(x), Mean(x)]
end proc:

Nevertheless you must be very carefull with the "median".
In Probability/Statistics it is defined as the quantile of order 0.5, which means roughly that 50% of the observations (= of the numbers in your list) are smaller than the median and 50% larger.
For small samples, e.g [1, 2, 3, 8], the estimation of the median is a complex problem.
For instance every point in ]2, 3[ verify the requirement that 50% of the points are smaller than it: so what is the median? Your code returns 2.5, which is an acceptable value, but not more acceptable than 2.0001.
For very large samples this problems still exists but is often less crucial.
A robust estimation of the median can be obtained through resampling procedures (for instance Bootstrap, a procedure the Statistics package).

If the mean is not ambiguous, there is always a problem to define the median.

## Use the option "parameters" in dsolve...

sol := dsolve(SYS2, numeric, parameters=[n]):

# set the value of n ... n=1 for instance
N:=1:
sol(parameters=[N]):

# "initialize" the computation
tmax := 600.:
sol(tmax):

# plot the solution
odeplot(sol, [t, x(t)], t=0..tmax, title=cat("n=", N))

## I suggest you to replaceInterpolation:-I...

I suggest you to replace
Interpolation:-Interpolate([seq(x, x = -2 .. 2, .1)], [seq(func(x, j), x = -2 .. 2, .1)], method = cubic)
by
CurveFitting:-Spline([seq(x, x = -2 .. 2, .1)], [seq(func(x, j), x = -2 .. 2, .1)], x, degree=1)  # I tested only with degree=1

I think you can also remove the option 'numeric' in the integration.

I keep having network to network transfer problem and I can't provide you an "improved" version of your code.
But the modifications are very light and I guess you will have no problem to use them by yourself.

Hope it will work.

## @maple2015  Very optimistic to...

Very optimistic of you to say it would take at least 10 minutes !
(it took more than 1.5 hour to me)

A hint (sorry I can't provide you the Maple code for a network to network transfert problem)

1. Comment your last "Determinant(KFF)" line and deplace it by
DetKFF := z -> Determinant(evalf(subs(P=z, KFF)));
2. To have an idea of what DetKFF(z) looks like do
plot('DetKFF(z)', z=0.01..5)
Do not forget the quotes !
3. It seems (zoom on the plot) that there is a first root around 0.15.
Execute
fsolve('DetKFF(z)', z=0.1)
You should get the answer  0.16999...

It'is impossible to hope finding a root of Determinant(KFF).
Since the computation of it is extremely time consuming (I killed the command before it ended).

Other hints:

1. do not try to start fsolve from z=0 (singularity for z=0)
2. if you have a close look to the plot near z=0 you will find numerical oscillations: they can avoided by increasing the value of "Digits" (to the detriment to the efficiency of plot and fsolve).

BTW: I did a little mistake in the numerical values

node 1 = (0,0)

node 2 = (0,1)

node 3 = (5,6)

node 4 = (6,6)

## Try TextBox ......

I keep using Maplets (quite unusual by these days), and I suggest you to try TextBox.
The idea is to create your own "InputDialog" with a TextBox inside (you can use the Maplet assistant for this).
Unfortunately I do not have MAPLE right now and I can't provide you a piece of code to whow how to proceed.
Let me know if still encounter problems and I will send you something later.

## PROBLEM SOLVED !!!...

I keep opened this question for any other person who could face this same problem.

Here is the solution in the case MyNewList contains the list of elements to add to MyList

DO NOT USE   Maplets :-Tools :-Set(DDB(itemlist)=MyNewList)

BUT
for k in MyNewList do
Maplets :-Tools :-Set(DDB(appenditem)=k)
end do;

The bold-written restriction above can generally be bypassed by a proper definition of MyList and of MyNewList

Hope this can help even if the Maplets seem old-fashioned

## It seems to work for me...

Hi,

I use maple 2016 on a Windows 7 PC.
I provide tou a screen capture of the Maple code (I can't upload a file by using the green arrow).
First thing : change search(...) text by StringTools:-Search(...)

PS : don't worry about the name of the file : the first test I made was saving x := [ evalf[10](Pi) ]

## Maybe you could try this ......

I may be mistaken, but it looks like you want to compute quantiles at regular intervals ???

q := i -> Quantile(GammaDistribution(4.5/100, 2.5), 1/(2*(N+1))+1/(N+1)*i, numeric) + 0.068

[Seq(q(i), i=1..(N-1))]

Note 1 : with Maple 2015 (Windows 7) your code returns me a "connection to server failed"

Note 2 : the sequence [seq(q(i), i=1..(N-1))]  runs very quickly : using Threads does not seem necessary

Note 3 : the CDF is a non decreasing function of its argument, and even here a strictly increasing one. As a consequence there should be only one solution to the "solve( (1/(2*(N+1))+1/(N+1)*i)=cdf(x),x)" command of yours.
In practice, for a reason I do not know, this command returns many solutions, some real and others complex (probably the reason for which you load the RealDomain package ?).
Using "Quantile" prevents these spurious solutions.

## could you try this ?...

I cannot provide you the piece of code I have written for computer-related problems
But what I did is sufficiently simple for me to give you a sketch of it

Step 1 :

EasySys := {diff(v(t), t)=0, diff(h(t), t)=w(t), siff(w(t), t)=0}  # if I am not mistaken
EasySol := dsolve ( EasySys, {v(t), h(t), w(t)})                       # which can be done manually

Step 2:

HarderSys := {diff(x1(t), t)=v(t)*cos(h(t)), diff(x2(t), t)=v(t)*sin(h(t))}
HarderSys := subs(EasySol, HarderSys):
HarderSol := dsolve(HarderSys, {x1(t), x2(t)})                        # easily found too

FullSol := EasySol union HarderSol;

I am not certain it is the solution you were searching for (no numerics here)
Probably someone will provide you a clever solution

Hope I helped

## try  printf("%g\n",p) to add a carr...

try  printf("%g\n",p) to add a carriage return and printf("%g\n\n",p) to skip a line after the print

 1 2 Page 2 of 2
﻿