mmcdara

6149 Reputation

17 Badges

9 years, 62 days

MaplePrimes Activity


These are answers submitted by mmcdara

Your problem is not completely defined.
There exist two ways to understand it:
 

restart:

# First question : are your dices distinct or not ?

randomize():

roll_1_dice := rand(1..6):

roll_2_dices := [roll_1_dice(), roll_1_dice()]

[4, 3]

(1)

# First case : distinct dice

# Sequence of all outcomes
# There are many ways to this, for instance


with(combinat, cartprod):
T := cartprod([[$1..6], [$1..6]]):
all_outcomes := NULL:
while not T[finished] do
  all_outcomes := all_outcomes, T[nextvalue]()
end do:
all_outcomes_D := [all_outcomes]

[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]]

(2)

# another way

M := Matrix(6, 6):
all_outcomes_D := [indices(M)]

[[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [6, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6]]

(3)

# still another one

all_outcomes_D := [seq(seq([i, j], j=1..6), i=1..6)]

[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]]

(4)

# Randomly pick an outcome
# Here again a solution among many others

combinat:-randperm(all_outcomes_D)[1]

[2, 1]

(5)

#  another solution

pick_D := rand(1..numelems(all_outcomes_D)): # equivalently rand(1..36):
all_outcomes_D[pick_D()]

[5, 3]

(6)

# Second case : undistinct dice

all_outcomes_U := [seq(seq([i, j], j=i..6), i=1..6)]

[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 3], [3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 5], [5, 6], [6, 6]]

(7)

#  Randomly pick an outcome

pick_U := rand(1..numelems(all_outcomes_U)):
all_outcomes_U[pick_U()]

[3, 4]

(8)

# test (distinct dice)

toss   := mul(roll_2_dices());
picked := mul(all_outcomes_D[pick_D()]);

if   toss < picked then "less"
elif toss = picked then "equal"
else                    "greater"
end if;

12

 

16

 

"less"

(9)

 


 

Download A_solution.mw

@9009134

 

For information here is the result the statistical software R produces (fit of CP/R by a 4th degree polynomial in T)

t <- c(298., 300., 400., 500., 600., 700., 800., 900., 1000.)
cp <- c(54.187, 54.518 , 70.421 , 84.683 , 96.982 , 107.323, 116.042, 123.801 , 131.594)
cpoverR <- cp / 1.987
lm(cpoverR ~ 1+t+I(t^2)+I(t^3)+I(t^4))  # linear fit


(Intercept)            t                    I(t^2)           I(t^3)            I(t^4)  
 2.579e+00    7.263e-02    7.326e-05   -1.512e-07    6.895e-11  


Which means the model R finds is 2.579 + 7.263e-02*t + 7.326e-05*t^2 -1.512e-07*t^3 + 6.895e-11*t^4
Practically identical to the model I found "by hand".
 


A way to force LinearFit is to operate on SCALED data.
Here is an illustration for the model CP/R = f(T)
Now LinearFit and the "by hand" method (such as R) give the same result.

A remark for people from the development team that could read your thread.
I consider that a clever implementation of LinearFit should account for ill condionned problems.
Solutions are well known 

  • normalize the data (as I did here)
  • use methods less sensitive to bad condionning (Givens-Householder for instance)
  • use othogonal polynomials and express the result in canonical basis
     

restart:

with(Statistics):

T := [298., 300., 400., 500., 600., 700., 800., 900., 1000.];

CP := [54.187, 54.518 , 70.421 , 84.683 , 96.982 , 107.323, 116.042, 123.801 , 131.594];

[298., 300., 400., 500., 600., 700., 800., 900., 1000.]

 

[54.187, 54.518, 70.421, 84.683, 96.982, 107.323, 116.042, 123.801, 131.594]

(1)

R := 1.987;

1.987

(2)

# Let's try to scale the data (case of T and CP only)

Tscaled  := Scale(T):
CPscaled := Scale(CP/~R):

Tscaled, CPscaled;

`Cp/R`    := theta -> theta^4*a5+theta^3*a4+theta^2*a3+theta*a2+a1;

M1scaled := LinearFit(`Cp/R`(theta), Tscaled, CPscaled, theta);

Matrix(9, 1, {(1, 1) = HFloat(-1.2154612619718141), (2, 1) = HFloat(-1.207691978337051), (3, 1) = HFloat(-0.8192277965989003), (4, 1) = HFloat(-0.43076361486074943), (5, 1) = HFloat(-0.04229943312259854), (6, 1) = HFloat(0.34616474861555213), (7, 1) = HFloat(0.7346289303537028), (8, 1) = HFloat(1.1230931120918535), (9, 1) = HFloat(1.5115572938300046)}), Matrix(9, 1, {(1, 1) = HFloat(-1.3453854645769592), (2, 1) = HFloat(-1.333995104145723), (3, 1) = HFloat(-0.7867416300584438), (4, 1) = HFloat(-0.2959581904637911), (5, 1) = HFloat(0.12727456316287933), (6, 1) = HFloat(0.48312868952923926), (7, 1) = HFloat(0.7831666091417269), (8, 1) = HFloat(1.0501690435465787), (9, 1) = HFloat(1.318341483864494)})

 

proc (theta) options operator, arrow; theta^4*a5+theta^3*a4+theta^2*a3+theta*a2+a1 end proc

 

HFloat(0.16917822809413155)+HFloat(0.9812133698557858)*theta-HFloat(0.22397858937737267)*theta^2+HFloat(0.020173883967869902)*theta^3+HFloat(0.020702898675047213)*theta^4

(3)

# Back to the original variables

ScaledCPoverR := eval(M1scaled, [theta = (theta - Mean(T)) / StandardDeviation(T)]);

CPoverR := ScaledCPoverR * StandardDeviation(CP/~R) + Mean(CP/~R);

-HFloat(2.159324034212451)+HFloat(0.003811662488315613)*theta-HFloat(0.22397858937737267)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^2+HFloat(0.020173883967869902)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^3+HFloat(0.020702898675047213)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^4

 

HFloat(15.366996346473783)+HFloat(0.05574515184793432)*theta-HFloat(3.275662657384246)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^2+HFloat(0.2950408722175395)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^3+HFloat(0.3027776551231061)*(HFloat(0.003884641817381508)*theta-HFloat(2.3730845235515035))^4

(4)

M1unscaled:= expand(%);

HFloat(2.5793789487674212)+HFloat(0.07262797433002269)*theta+HFloat(7.325618169228684e-5)*theta^2-HFloat(1.511850442093991e-7)*theta^3+HFloat(6.89489640013437e-11)*theta^4

(5)

span            := unapply(subs([seq(a||i=1, i=1..5)], [op(`Cp/R`(theta))]), theta):
DesignMatrix    := convert(span~(T), Matrix):
D2Matrix        := (DesignMatrix^+ . DesignMatrix)^(-1):
ByHandSolution  := Vector(5, i -> a||(6-i))
                   =
                   D2Matrix . DesignMatrix^+ . convert(CP/~R, Vector):

M1ByHand := convert(span(theta), Vector[row]) . rhs(ByHandSolution);

HFloat(2.579378948829685)+HFloat(6.894896400274164e-11)*theta^4-HFloat(1.5118504421633464e-7)*theta^3+HFloat(7.325618168985484e-5)*theta^2+HFloat(0.07262797432690293)*theta

(6)

plots:-display(
  ScatterPlot(T, CP/~R),
  plot(M1unscaled, theta=min(T)..max(T), color=blue, legend='LinearFit'),
  plot(M1ByHand, theta=min(T)..max(T), color=red, legend='ByHand'),
  gridlines=true
);

 

plot(M1unscaled-M1ByHand, theta=min(T)..max(T), title="difference between models", gridlines=true)

 

 


 

Download FITTING_after_scaling.mw

Here are fittings obtained the least squares method.

You will see that the Maple procedure LinearFit suffers a lot of problems :

  1. It retuns a warning saying the (information) matrix is not of full rank.
    I show it is the case for Digits=10 (default value), but that this same matrix is of full rank for a large enough value of Digits (here 40). In my opinion this denotes a weakness of LinearFit
  2. For the model S/T=f(T) (written this way, but a clever way would be to fit S=g(T) and next write S/T = g(T)/T...) LinearFit returns a completely absurd error (Error, (in Statistics:-LinearFit) the model, `S/T)`(theta), is not linear in the parameters, [])

So I completed the use of LInearFit with a "By hand" construction of the models (an extremely easy thing to do if you have basic knowledge about the ordinary least squares method).
The "rank problem" can be easily avoided and no "error" (as expected) occur when proceeding this way.

In my opinion I consider LinearFit suffers some weaknesses

I didn't try to use NonlinearFit instead of linearFit as a workaround because it is just stupid given all your models are linear.

Download FITTING.mw

Now, a little advice about the "good practices in linear regression".
A good way to fit statistical models is to begin by looking at the data and infer some simple model (for instance a low degree polynomial model).
If you do thys for the CP/R=f(T) model you will see it's mainly linear with only a slight discrepancy that indicates adding a quadratic term could be sufficient.
So, try to fit CP/R to the model a0+a1*T and if the result doesn't suit you fit the model a0+a1*T*a2*T^2 (and augment it if you want.

Of course (assuming no warnong or error occurs) the higher the number of parametrers (= 1+degree of the model), the lower the residual sum of squares (RSS), providing this number doesn't exceed the number of observations (9 in your case).
Let's suppose you fit polynomial models of degree d and denote by RSS(d) the value of RSS for the polynomial model of degree d ; then RSS(0) > RSS(1) > ... > RSS(8) = 0 (with your 9 data).
But be extremely careful, RSS is NOT the good criteria to use to select the best model among these d-1 models.

No other solution than the trivial one if sin(y) <> 0

PS : Of course, if y=k*Pi  (k in Z) , then any function which respects the boundary conditions is solution. for instance GenFunc(x) = (1-cos(x*2*Pi/a))
 

``

restart:

w := sin(y)*GenFunc(x)

sin(y)*GenFunc(x)

(1)

# given all the dij are identical, Nx=Ny and Nxy=0 we have

EDO := D__11*diff(w, x$4)+6*D__11*diff(w, [x$2, y$2])+D__11*(diff(w, y$4))+N__x*(diff(w, x$2))+N__x*(diff(w, y$2))

D__11*sin(y)*(diff(diff(diff(diff(GenFunc(x), x), x), x), x))-6*D__11*sin(y)*(diff(diff(GenFunc(x), x), x))+D__11*sin(y)*GenFunc(x)+N__x*sin(y)*(diff(diff(GenFunc(x), x), x))-N__x*sin(y)*GenFunc(x)

(2)

EDO := simplify(EDO)

sin(y)*(D__11*(diff(diff(diff(diff(GenFunc(x), x), x), x), x))-6*D__11*(diff(diff(GenFunc(x), x), x))+D__11*GenFunc(x)+N__x*(diff(diff(GenFunc(x), x), x))-N__x*GenFunc(x))

(3)

EDO := op(2, EDO);

D__11*(diff(diff(diff(diff(GenFunc(x), x), x), x), x))-6*D__11*(diff(diff(GenFunc(x), x), x))+D__11*GenFunc(x)+N__x*(diff(diff(GenFunc(x), x), x))-N__x*GenFunc(x)

(4)

# To see what happens, set boundary conditions at x=0 alone.

SOL := unapply(rhs(dsolve({EDO=0, GenFunc(0) = 0, D(GenFunc)(0) = 0})), x);
 

proc (x) options operator, arrow; (-(1/2)*((D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)+(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*_C3/(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)-(1/2)*((D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)-(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*_C4/(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*exp(-(1/2)*2^(1/2)*(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)*x/D__11)+(-(1/2)*((D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)-(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*_C3/(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)-(1/2)*((D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)+(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*_C4/(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2))*exp((1/2)*2^(1/2)*(D__11*(6*D__11-N__x-(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)*x/D__11)+_C3*exp(-(1/2)*2^(1/2)*(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)*x/D__11)+_C4*exp((1/2)*2^(1/2)*(D__11*(6*D__11-N__x+(32*D__11^2-8*D__11*N__x+N__x^2)^(1/2)))^(1/2)*x/D__11) end proc

(5)

# Obviously Genfunc(x) is not identically null unless _C3=_C4=0

evalf(eval(SOL(0.01), {D__11=10000, N__x=1000}));
evalf(eval(SOL(0.02), {D__11=10000, N__x=1000}));

0.277112e-3*_C3+0.281574e-3*_C4

 

0.1099684e-2*_C3+0.1135393e-2*_C4

(6)

# let's find _C3 and _C4 such that SOL(a)=D(SOL)(a)=0 :

DSOL := unapply(diff(SOL(x), x), x):
solve({SOL(a)=0, DSOL(a)=0}, {_C3, _C4})

{_C3 = 0, _C4 = 0}

(7)

# thus the only solution is GenFunc(0)=0 ... QED

0

(8)

 


 

Download N0_Other_Solution.mw

Here is something wich looks like what you want.
Colors are randomly choosen, so the result is not always pretty (there is a randomize() command at the top of the worksheet to generate a random seed which will enable to obtain different colourings). 
You can of course define your own colors.

To obtain something closer to the picture tou present it would be necessary to rescale the radii of the vertices of each graph, a thing I didn't do here.

Left : graph1 ; middle : graph 2 ; right carteian product of g1 and g2.
Cartesian_Product_of_Graphs.mw

Many errors.

choosesystem := Maplet(.....):
Maplets[Display](maplet):

is not correct, this is probably what you wanted to do ?

maplet := Maplet(.....):
choosesystem := Maplets[Display](maplet):



Next, (look the construction of InputDialog in the help pages)

 Maplet(InputDialog['ID1']("Choose system?", 'Yes1' = Shutdown(['Yes']), 'No1' = Shutdown(['No']))):

is not correct : neither 'Ye1' nor'No1' are options of an InputDialog element. The correct syntax is (for instance, for you can exchange onapprove and oncancel)

 Maplet(InputDialog['ID1']("Choose system?", 'onapprove' = Shutdown(['Yes']), 'on cancel' = Shutdown(['No']))):

 

 

More of this : 

Shutdown(['Yes'])

means : "return the content of element named 'Yes'", which doesn't exist, so another mistake.
Mybe you wanted to return "Yes" ? In this cas write 

Shutdown(["Yes"])





Let me be more constructive now: personnaly I wouldn't have used InputDialog but RadioButton to do this.
Here is the way I would do that (but it's just my opinion and you could prefer to do it otherwise)

 

restart:

with(ListTools):

with(Maplets[Elements]):

f := proc(text)
  local maplet, choice:
  maplet := Maplet(
    [
      Label(text),
      [
        RadioButton['RB1']("yes", 'value'=true, 'group'='BG1'),
        RadioButton['RB2']("no", 'value'=false, 'group'='BG1')
      ],
      [
        Button("OK", Shutdown(['RB1', 'RB2']))
      ]
    ],
    ButtonGroup['BG1']()
  ):
  choice := Maplets[Display](maplet):
  `if`(parse(choice[1]), "yes", "no");
end proc:

result1 := f("Choose system?");      #select the "yes" button
result2 := f("Like and it works?")   #select the "no" button

"yes"

 

"no"

(1)

 


 

Download Maybe_this.mw

To complete Preben's reply,
if you only want to plot a set of points whose co-ordinates are contained in 2 vectors, possibly with undefined elements, plot or ScatterPlot can do the job without prior selection of the points with both real co-ordinates.
 

restart;

with(RealDomain):

roll := rand(-3.0..5.0):
p := <seq(roll(), i=1..10)>:
q := sqrt~(p):
p,q;

Statistics:-ScatterPlot(p, q, labels=['p', `sqrt(p)`], axes=normal);

Vector(10, {(1) = 4.418130698, (2) = 1.413665415, (3) = .838744609, (4) = -.244301281, (5) = 3.676432597, (6) = -1.645261861, (7) = 4.190905574, (8) = -2.412421905, (9) = 4.528147374, (10) = 1.572161447}), Vector(10, {(1) = 2.101934989, (2) = 1.188976625, (3) = .9158300110, (4) = Float(undefined), (5) = 1.917402565, (6) = Float(undefined), (7) = 2.047170138, (8) = Float(undefined), (9) = 2.127944401, (10) = 1.253858623})

 

 

plot([ seq([p[i], q[i]], i=1..10) ], style=point, labels=['p', `sqrt(p)`])

 

# points whose 2nd component is real

pq := [ seq(<p[i], q[i]>, i=1..10) ]:
Statistics:-Select(t->is(t[2], real), pq)

[Vector(2, {(1) = 4.418130698, (2) = 2.101934989}), Vector(2, {(1) = 1.413665415, (2) = 1.188976625}), Vector(2, {(1) = .838744609, (2) = .9158300110}), Vector(2, {(1) = 3.676432597, (2) = 1.917402565}), Vector(2, {(1) = 4.190905574, (2) = 2.047170138}), Vector(2, {(1) = 4.528147374, (2) = 2.127944401}), Vector(2, {(1) = 1.572161447, (2) = 1.253858623})]

(1)

 


 

Download undefined.mw

@mlheldwein 

Here is another way using convolution and Fourier transform.
(notional examples...adjust the length of the window and the period in example 2).


 

restart;

with(plots):

x:=10+1.5*t+3*sin(2*Pi*(5)*t+2);


X     := unapply(x, t);
H     := t -> 2*(Heaviside(t+0.5)-Heaviside(t));
X_avg := t -> int(X(tau)*H(t-tau),tau=-infinity..+infinity);


plot([X(t), X_avg(t)],t=0..3, legend=["x","X_avg"], axes=boxed);
 

10+1.5*t+3*sin(10*Pi*t+2)

 

proc (t) options operator, arrow; 10+1.5*t+3*sin(10*Pi*t+2) end proc

 

proc (t) options operator, arrow; 2*Heaviside(t+.5)-2*Heaviside(t) end proc

 

proc (t) options operator, arrow; int(X(tau)*H(t-tau), tau = -infinity .. infinity) end proc

 

 

XF    := eval(inttrans:-fourier(X(t), t, xi));
HF    := eval(inttrans:-fourier(H(t), t, xi));
FF    := XF*HF:
X_avg := eval(inttrans:-invfourier(FF, xi, t));

plot([x, X_avg],t=0..3, legend=["x","X_avg"], axes=boxed);

Pi*((3*I)*Dirac(xi+10*Pi)*exp(-2*I)-(3*I)*Dirac(xi-10*Pi)*exp(2*I)+(3*I)*Dirac(1, xi)+20*Dirac(xi))

 

(2*I)*(-exp(((1/2)*I)*xi)+1)/xi

 

(1/40)*(60*Pi*t+415*Pi+48*cos(10*Pi*t+2))/Pi

 

 

X    := t -> piecewise(t<0, 0,  t<1, t, t<2, 2-t, 0):
Xper := sum(X(t-2*k), k=0..10):

plot(Xper, t=0..5);

XF    := eval(inttrans:-fourier(Xper, t, xi)):
FF    := XF*HF:
X_avg := eval(inttrans:-invfourier(FF, xi, t)):

plot([Xper(t), X_avg],t=0..10, legend=["x","X_avg"], axes=boxed);

 

 

 


 

Download Using_Convolution.mw

I don't know, maybe the expression becomes too complex with the original form of ode2 and Maple is trapped somewhere???

In such a case I always try to use a simpler form of the ode to make sure to avoid this kind of preoblem.
For instance try this

sol := dsolve({diff(Q(t),t)=A*t^B*Q(t)+C, Q(0)=S}, Q(t))

The last line replaces A, B and S by their values in the original form of ode2
 

restart

sol := dsolve({diff(Q(t),t)=A*t^B*Q(t)+C, Q(0)=S}, Q(t))

Q(t) = (C*(A/(B+1))^(-1/(B+1))*((B+1)^2*t^(B/(B+1)+1/(B+1)-B-1)*(A/(B+1))^(1/(B+1))*(B^2*t^(B+1)*A/(B+1)+B^2+2*t^(B+1)*A*B/(B+1)+3*B+t^(B+1)*A/(B+1)+2)*(t^(B+1)*A/(B+1))^(-(1/2)*(B+2)/(B+1))*exp(-(1/2)*t^(B+1)*A/(B+1))*WhittakerM(1/(B+1)-(1/2)*(B+2)/(B+1), (1/2)*(B+2)/(B+1)+1/2, t^(B+1)*A/(B+1))/((B+2)*(2*B+3)*A)+(B+1)^2*t^(B/(B+1)+1/(B+1)-B-1)*(A/(B+1))^(1/(B+1))*(B+2)*(t^(B+1)*A/(B+1))^(-(1/2)*(B+2)/(B+1))*exp(-(1/2)*t^(B+1)*A/(B+1))*WhittakerM(1/(B+1)-(1/2)*(B+2)/(B+1)+1, (1/2)*(B+2)/(B+1)+1/2, t^(B+1)*A/(B+1))/((2*B+3)*A))/(B+1)+S)*exp(t^(B+1)*A/(B+1))

(1)

eval(sol, [A=-alpha*beta, B=beta-1, C=-a*p^b]):

 


 

Download workaround.mw

You will find nothing with CurveFitting ar any other smoothing strategy.
The best thing to do is to refine your "x" points (or 'i"), for instance by writting :

seqi := [seq(-10..10, h)]:  # where h << 1
for i inseqi do
...
end do:
ptsN1 := [seq(..., i in seqi)
]:  # no need to use CodeTools:-Usage 


But if you do this you still won't be able to see anything for the peaks are concentrated in the ranges -4.35..-4.1 and 4.1..4.35
To verify this, just do
seqi :=  [seq(-4.35..4.1, 0.01)]:  # for the peak at negative location.

 

PS : Some remarks:

  • There is no need to define d[i]:=i
    Replace all occurrences of d[i] by i
  • There is no need to define all inner variables  under the form variable[i].
    For instance write lambda1 instead of lambda[i]
  • The only exception is for f.
    Before the loop write ptsN1:=NULL:
    And inside the loop replace 
    f[d[i]]:=map(fnormal, evalf(h1[i]*(no*J1mod[i]+Omega^2*J2mod[i]))):
    by
    ptsN1 := ptsN1, [i, h1*Omega^2*J2mod ]:
    (for you have n0:=0 ; more of this map and fnormal are useless).
    After end do write 
    ptsN1 := [ptsN1]:
    This will avoid the further definition of ptsN1
  • The for loop contains a lot of things that are constant and should displaced outside (a, b, ...)
    In particular 

    J2[i]:=sum(g1[i]*J1[i]+g1[i]*F2[i],k=1..1);
    Should be replaced by J2:=g1*(J1+F2); for k=..1 means k=1.

  • The command 
    g1[i]:=0.5*sqrt(Pi)*tau0*exp(c2^2) *exp(-conjugate(a)*((k-1)*xr)^2)/(sqrt(conjugate(a)));

    Can be displaced outside of the loop because g1 is a constant.
    More of this, as k=1 (see above), it should be written
    g1 :=0.5*sqrt(Pi)*tau0*exp(c2^2) /(sqrt(conjugate(a)));
     
  • etc
     

I do not know if this code is yours or if it is somebody's else, but I believe you must do a huge effort to (re)write it in a more clever way. 
As it is I doubt you will find someone patient enough to do this job in your place and provide you more advices than I already did.

 

 

 

Firstly the abscissas of your 12 points are 1, 2, ... 12, so I don't understand how you can say the period is 12, you need to add either the point x=0 or either the point x=13 to be able to say that.

Next: you say nothing about the type of function you want to draw. Dharr gave you a solution which is just one amid an infinity of solutions.
Do you wanr to interpolate the points or approximate them?

Here is a solution using interpolation.
The global function is not constructed but it is (formally) very simple to do if you need it, see here Dirac_comb
 

``

restart:

p := [[1, 353913], [2, 286917], [3, 1494917], [4, 644834], [5, 399736], [6, 549314], [7, 963371], [8, 786619], [9, 328973], [10, 645844], [11, 1198539], [12, 302957]]:

# periodisation (period=12) by ading the point [13, p[1][2]]

P         := [p[], [13,p[1][2]]];

# spline interpolation (you can change the degree)

si := unapply( CurveFitting:-Spline(P, t, degree=2, endpoints='natural'), t):

# basic spline pattern

pattern := t -> piecewise(t >=1 and t <= 13, si(t), 0);

# basic spline pattern

plots:-display(
  plot(P, style = point, color = red, symbol = solidcircle, symbolsize = 15),
  plot(pattern(t), t= -1 .. 15, color = blue, discont=true)
)

[[1, 353913], [2, 286917], [3, 1494917], [4, 644834], [5, 399736], [6, 549314], [7, 963371], [8, 786619], [9, 328973], [10, 645844], [11, 1198539], [12, 302957], [13, 353913]]

 

proc (t) options operator, arrow; piecewise(1 <= t and t <= 13, si(t), 0) end proc

 

 

# Now draw translated replicates of the pattern

plot([seq(piecewise(t >=1+12*k and t <= 13+12*k, pattern(t-12*k), 0), k=-4..4)], t=-48..49, discont=true, size=[1000, 400])

 

NULL

 

Download Pattern_periodisation.mw

If you prefer Dharr solution AND you 12 points, then consider the period is 11 (not 12) and modify Dharr's code this way (note n=1..5 instead of n=1..3 to obtain an interpolator, and that the period is 11. and not 11 to get a faster output).
WATCHOUT:if you do this y[1] MUST BE EQUAL to y[12]

f := (1/2)*a[0]+add(a[n]*sin(2*n*Pi*t/(11.))+b[n]*cos(2*n*Pi*t/(11.)), n = 1 .. 5);
 
fn := LeastSquares(p, t, curve = f);
fnplot := plot(fn, t = -12 .. 24, color = blue)
plots:-display(P, fnplot);


Fit_2.mw

restart:
interface(version)
Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895

with(Units[Natural]):
cos(45*Unit(degrees));
sin(90*Unit(degrees));

And in more concise way :
 

with(Units[Natural]):
d := 1*Unit(degrees): 
cos(45*d); 
sin(90*d);

 

Hi, 

Here is a way you maybe consider as more elegant (but I rarely use it and I prefer doing what you do yourself, that is generating uniform random numbers and "inverting" an empirical cdf...).

The UseHardwareFloats := false: instruction is usefull to convert S into a sequence of integers (look the Sample help page).
What I do not like hereare the multiple conversions this solution needs (use of round and conversion as list). I let you judge this by yourself
 

restart

with(Statistics):

Probs := [0.10, 0.30, 0.20, 0.25, 0.15]:
Bins  := [50, 60, 70, 80, 90]:

X := RandomVariable(ProbabilityTable(Probs));

_R

(1)

UseHardwareFloats := false:

N := 4:
S := round~(Sample(X, Vector(N, datatype=float))):

Bins[convert(S, list)]

[80, 60, 60, 80]

(2)

 

 

Download A_way.mw

Here is another way where I use "EmpiricalDistribution" instead of "Probability Table"
Download Another_way.mw

Try to do a few prior simplifications, for instance by setting  a = 2*h/e0, b=t/(2*(-h^2-omega^2)), and so on.
Next integrate x*expand(E) instead of x*E
Apply combine(.. trig) tio the result
...
Is it enough for you ?


 

restart

with(LinearAlgebra):

``

# next set 2*h/e0 = a

E := e0*(1+2*a*(sinh('beta')+a)/(1-a*sinh('beta')));

# with

'a' = 2*h/e0

e0*(1+2*a*(sinh(beta)+a)/(1-a*sinh(beta)))

 

a = 2*h/e0

(1)

# now beta ...

beta := c*(x+b);


# with

'b' = t/(2*(-h^2-omega^2));

# and

'c' = e0*sqrt(1+a^2);

c*(x+b)

 

b = t/(-2*h^2-2*omega^2)

 

c = e0*(a^2+1)^(1/2)

(2)

iE0 := int(x*E, x)

-(1/2)*e0*x^2-4*e0*b*arctanh((1/2)*(2*exp(c*(x+b))*a-2)/(a^2+1)^(1/2))*a^2/(c*(a^2+1)^(1/2))-4*e0*b*arctanh((1/2)*(2*exp(c*(x+b))*a-2)/(a^2+1)^(1/2))/(c*(a^2+1)^(1/2))-2*e0*ln((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))*b*a^2/(c*(a^2+1)^(1/2))-2*e0*ln((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))*b/(c*(a^2+1)^(1/2))-2*e0*ln((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))*x*a^2/(c*(a^2+1)^(1/2))-2*e0*ln((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))*x/(c*(a^2+1)^(1/2))+2*e0*ln((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))*b*a^2/(c*(a^2+1)^(1/2))+2*e0*ln((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))*b/(c*(a^2+1)^(1/2))+2*e0*ln((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))*x*a^2/(c*(a^2+1)^(1/2))+2*e0*ln((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))*x/(c*(a^2+1)^(1/2))-2*e0*dilog((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))*a^2/(c^2*(a^2+1)^(1/2))-2*e0*dilog((-exp(c*(x+b))*a+(a^2+1)^(1/2)+1)/(1+(a^2+1)^(1/2)))/(c^2*(a^2+1)^(1/2))+2*e0*dilog((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))*a^2/(c^2*(a^2+1)^(1/2))+2*e0*dilog((exp(c*(x+b))*a+(a^2+1)^(1/2)-1)/(-1+(a^2+1)^(1/2)))/(c^2*(a^2+1)^(1/2))

(3)

iE := simplify(algsubs(1+a^2=A^2, iE0)) assuming A > 0

(1/2)*e0*(4*A*b*c*ln(1+A)+4*A*c*x*ln(1+A)-4*A*b*c*ln(-exp(c*(x+b))*a+A+1)-4*A*c*x*ln(-exp(c*(x+b))*a+A+1)-8*A*arctanh((exp(c*(x+b))*a-1)/A)*b*c+4*A*ln((exp(c*(x+b))*a+A-1)/(-1+A))*b*c+4*A*ln((exp(c*(x+b))*a+A-1)/(-1+A))*c*x-c^2*x^2-4*A*dilog((-exp(c*(x+b))*a+A+1)/(1+A))+4*A*dilog((exp(c*(x+b))*a+A-1)/(-1+A)))/c^2

(4)

map(collect, iE, [c, b])

(1/2)*e0*(-c^2*x^2+((4*A*ln(1+A)-4*A*ln(-exp(c*(x+b))*a+A+1)-8*A*arctanh((exp(c*(x+b))*a-1)/A)+4*A*ln((exp(c*(x+b))*a+A-1)/(-1+A)))*b+4*A*ln(1+A)*x-4*A*ln(-exp(c*(x+b))*a+A+1)*x+4*A*ln((exp(c*(x+b))*a+A-1)/(-1+A))*x)*c-4*A*dilog((-exp(c*(x+b))*a+A+1)/(1+A))+4*A*dilog((exp(c*(x+b))*a+A-1)/(-1+A)))/c^2

(5)

expand(E);
map(int, x*%,x)

e0+2*e0*a*sinh(c*b)*cosh(c*x)/(1-a*sinh(c*b)*cosh(c*x)-a*cosh(c*b)*sinh(c*x))+2*e0*a*cosh(c*b)*sinh(c*x)/(1-a*sinh(c*b)*cosh(c*x)-a*cosh(c*b)*sinh(c*x))+2*e0*a^2/(1-a*sinh(c*b)*cosh(c*x)-a*cosh(c*b)*sinh(c*x))

 

(1/2)*x^2*(e0*x+2*e0*sinh(c*b)*ln(tanh((1/2)*c*x)-1)/(c*(sinh(c*b)+cosh(c*b)))-2*e0*sinh(c*b)*ln(tanh((1/2)*c*x)+1)/(c*(sinh(c*b)-cosh(c*b)))-4*e0*sinh(c*b)^2*arctan((1/2)*(2*(sinh(c*b)*a+1)*tanh((1/2)*c*x)+2*cosh(c*b)*a)/(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2))/(c*(sinh(c*b)-cosh(c*b))*(sinh(c*b)+cosh(c*b))*(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2))+2*e0*cosh(c*b)*ln(tanh((1/2)*c*x)-1)/(c*(sinh(c*b)+cosh(c*b)))+2*e0*cosh(c*b)*ln(tanh((1/2)*c*x)+1)/(c*(sinh(c*b)-cosh(c*b)))+4*e0*cosh(c*b)^2*arctan((1/2)*(2*(sinh(c*b)*a+1)*tanh((1/2)*c*x)+2*cosh(c*b)*a)/(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2))/(c*(sinh(c*b)-cosh(c*b))*(sinh(c*b)+cosh(c*b))*(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2))-4*e0*a^2*arctan((1/2)*(2*(sinh(c*b)*a+1)*tanh((1/2)*c*x)+2*cosh(c*b)*a)/(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2))/(c*(sinh(c*b)^2*a^2-cosh(c*b)^2*a^2-1)^(1/2)))

(6)

map(combine, %, trig)

(1/2)*x^2*(-4*e0*a^2*arctan((tanh((1/2)*c*x)*sinh(c*b)*a+cosh(c*b)*a+tanh((1/2)*c*x))/(-a^2-1)^(1/2))+(-a^2-1)^(1/2)*c*e0*x-2*(-a^2-1)^(1/2)*ln(tanh((1/2)*c*x)+1)*e0+2*(-a^2-1)^(1/2)*ln(tanh((1/2)*c*x)-1)*e0-4*e0*arctan((tanh((1/2)*c*x)*sinh(c*b)*a+cosh(c*b)*a+tanh((1/2)*c*x))/(-a^2-1)^(1/2)))/(c*(-a^2-1)^(1/2))

(7)

 


 

Download Is_it_enough.mw

A solution among other 
`y'`

 

First 37 38 39 40 41 42 43 Last Page 39 of 52