Carl Love

Carl Love

28110 Reputation

25 Badges

13 years, 120 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

First, change all < to <=. The optimizer can't handle <. Then do:

Optimization:-NLPSolve(lhs(obj), [const[], obj], 'maximize');

Perhaps you meant sqrt(x-6) rather than sqrt(x-5)? Otherwise, there's no reason why they should "combine".

@a_simsim If you change the command copy(nodeprop) to copy(nodeprop, 'deep'), then you'll get your expected results. This is because not merely the Records themselves but also the Vectors in the Records are mutable structures, which means that a direct assignment merely creates a new pointer to the original structure rather than a new structure. The keyword deep means that copy is recursively applied to all substructures.

There is a blatant bug that can be seen in lines 5-6 of showstat(Statistics:-DataSummary): The X data themselves are being used as the weights, while the weights that you passed (as Y) are totally ignored. It's exactly as if it were behaving correctly and you had specified DataSummary(X, weights= X).

The command is GraphTheory:-SetVertexPositions.

X:= Matrix(9, 9, [[0, 0, 1, 0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0]]):

#Coordinates
P:= [[40, 40], [22, 22], [36, 26], [21, 45], [45, 35], [55, 20], [55, 45], [26, 59], [55, 65]]:

GT := GraphTheory;
G := GT:-Graph(X);
GT:-SetVertexPositions(G, P);
GT:-DrawGraph(G);

It is interesting that the position information is stored in the graph itself rather than simply in the plot. Also, note that SetVertexPositions modifies its first argument, the graph, rather than giving a return value.

You need to use all vertices, in order, in a list; so, tweaking is best done by alternating calls to GetVertexPositions and SetVertexPositions. Several examples are shown at help page ?GraphTheory,GetVertexPositions.

Is this what you're looking for?

restart:
A:= <
   1.364, 0.64765768e-1  ; 
   2.05,  -.182176113    ; 
   2.664, -0.13914542e-1 ; 
   2.728, 0.2193938e-1   ; 
   4.092, -0.18349139e-1 ; 
   4.1,   -.312968801    ; 
   5.328, -0.1819837e-2  ; 
   5.456, -.28840961     ; 
   6.15,  -.57076866     ; 
   7.992, .175022254
>: 
F:= unapply(CurveFitting:-LeastSquares(A, x), x):
P:= plot(
   [F, A], 0..8, color = [red, blue], style = [line, point],
   legend= ["Метод наименьших квадратов", "Экспериментальные данные"], 
   legendstyle= [font = ["Roman", 15]],
   labels= [typeset(d, ", ", `мм`), typeset(ln(`I__ `/I__0))], labelfont = ["Roman", 15],
   axesfont= ["ROMAN", "ROMAN", 15], linestyle = [solid], symbolsize = 20, 
   title= "Определение линейного коэффициента поглощения", titlefont = [Roman, bold, 20]
);
X:= A[..,1]:  Y:= A[..,2]:  `Y^`:= F~(X):
plots:-display(
   [
      P,
      Statistics:-ErrorPlot(
         `Y^`, xcoords= X, yerrors= abs~(Y-`Y^`), markers= false, thickness= 0
      )
   ],
   axes= normal, gridlines= false
);

Rather than putting an upper bound on k in the for loop, you could put an upper limit on the time your willing to spend on the computation. Here's my version:

Wrapped_prime:= proc(p::prime, {base::posint:= 10, filter::anything:= (()-> true)})
global lastK;
local pow:= base^trunc(ln(p)/ln(base)), b2:= base^2, k, m:= p;
   lastK:= 0;
   for k do
      #Recursive computation of repunit-wrapped number:
      pow:= b2*pow;  m:= pow + base*m + 1;
      if filter(k) then 
         if isprime(m) then return k fi;
         lastK:= k
      fi
   od
end proc
:     

Since repunits exist in any base, not just base 10 (Mersenne numbers being the most-famous example), the procedure will work in any base, defaulting to 10. The keyword parameter filter lets you specify a filtering of the k values, for your example, it's filter= (k-> irem(k,6) = 0). The  global lastK lets you check what was last value of k for which the wrapped number was verified composite by isprime.

The first argument to timelimit is the number of seconds of CPU time to expend before giving up.

timelimit(5, Wrapped_prime(397, filter= (k-> irem(k,6)=0)));
Error, (in isprime) time expired
lastK;
                              1656
timelimit(5, Wrapped_prime(397, base= 5));
                               2
timelimit(5, Wrapped_prime(397, base= 2));
                               24

 

Your system of equations contains numerous terms of the form

sum(FyjR, j = 1 .. m),

which makes it seem as if you believe that FyjR can be indexed by j; it can't be. That sum evaluates to simply m*FyjR.

Maple's mod is built to do computations in higher algebraic structures (such as rings of polynomials and matrices) built on top of the ring of integers modulo m. Thus, unevaluated variables such as your n are treated as transcendentals (or "dummy variables") in a polynomial, so n mod 2 is truly equal to n. In your case, you want n to represent an integer (which presumably will be supplied later), not a transcendental. In that case you should use irem(n,2) instead of mod(n,2).

While I strongly recommend that you use irem instead mod for this situation, Tom Leslie shows that you can use mod(n,x) if both and x are unevaluated and integer values will be supplied for both simultaneously, or at least n is supplied before x.

Okay, you're running the command-line version of Maple interactively. Let's suppose that the file that you created with Vim is named "C:/dir1/dir2/MyCode.mpl". Then, at the ">" cursor/prompt, enter

read "C:/dir1/dir2/MyCode.mpl";

The fact that your function involves exp is insignificant. You need numeric values and/or ranges for the variables ta, and eps or else clearly you'll be "unable to evaluate the function to numeric values". Also, we must have -2 < a < 2 to avoid complex values. 

Try this command:
Explore(
   plot(2*cos(t)/sqrt((1+exp(-eps*t))*(4/a^2-1)), t= -Pi..Pi, view= [DEFAULT, -2..2]), 
   a= 0.1..1.9, eps= 0.0..1.0
);

This'll let you control the values of a and eps with sliders.

Here's what your final plot should look like, more-or-less (the colors, arrow size, etc., are up to you):

This shows that the Euler's method solution is very wrong! That's the point of the problem. The step size is too large.

If you didn't get a plot like above, show your code, and we'll suggest corrections.

It's easy. Let be the adjacency matrix; so, in this case, is evaluated at the solution, just as you've shown in the PDF. Then

GT:= GraphTheory:
G:= GT:-Graph(A);
GT:-DrawNetwork(G);

 

The relevant indefinite sums (i.e., for an arbitrary number of terms) for this problem can be done symbolically, and this provides an interesting alternative solution. This type of symbolic analysis is often useful for time series, where the ordinate data are usually simple sequences of indefinite length.

Also, note that there are slightly different formulas for the standard deviation of a sample and of a population. The other Answers and Replys have used the sample formula. It's not clear to me that that's appropriate in this case. So, my code below uses the slightly simpler population formula.

SymbMean:= (f::algebraic, k::(name= range(algebraic)))-> 
   simplify(sum(f,k)/(rhs(rhs(k))-lhs(rhs(k))+1)):
SymbVar:= (f::algebraic, k::(name= range(algebraic)))-> 
   simplify(SymbMean(f^2,k) - SymbMean(f,k)^2):
SymbSD:= (f::algebraic, k::(name= range(algebraic)))->
   sqrt(SymbVar(f,k)):

Usage:
(mu,sigma)=~ Symb||(Mean,SD)(k, k= 1..n); eval(%, n= 20);

                                              (1/2)
                 1     1          1 /   2    \     
            mu = - n + -, sigma = - \3 n  - 3/     
                 2     2          6                
                       21          1     (1/2)
                  mu = --, sigma = - 1197     
                       2           6          
(mu,sigma)=~ Symb||(Mean,SD)(k^3, k= 1..n); eval(%, n= 30);

       1        2            1  
  mu = - (n + 1)  n, sigma = -- 
       4                     84 

                                                         (1/2)
    /     6         5        4         3         2      \     
    \567 n  + 1764 n  + 882 n  - 1764 n  - 1617 n  + 168/     
                 14415          1              (1/2)
            mu = -----, sigma = -- 456873536868     
                   2            84                  

 

Your instructions say to use a for loop. In Maple, using a for loop for something like this is not necessary, and even a bit unusual and inefficient (unless one is using compiled code or evalhf). But here it is:

Mean:= proc(X::seq(algebraic))
local S:= 0, x;
   for x in X do S:= S+x od;
   S/nargs
end proc
:
Mean(seq(k^3, k= 1..30));

Since the variance and standard deviation can be expressed as simple functions of the mean, using a for loop for those is just ridiculous.

Here's a little procedure that creates a new random variable from any real-valued algebraic combination of any number of any independent random variables with finite support (hence discrete). The new random variable will be treated with the same respect and efficiency by the Statistics package as the originals. The underlying random variables need not be identically distributed, nor equiprobable, nor have their support be a range of integers. So, if I've read the other Answers and Replys correctly, I believe that this does everything that they do and more.

restart
:
St:= Statistics
:
CombineDiscrete:= proc(R::list(RandomVariable), f)
uses S= Statistics, It= Iterator;
local r, X, t, P:= table(sparse), nR:= nops(R), fX;
   for X in 
      It:-CartesianProduct(
         seq([solve~(op~(indets(S:-PDF(r,t), specfunc(Dirac))), t)[]], r= R)
      )
   do
      P[(fX:= f(seq(X)))]:= P[fX] + mul(S:-Probability(R[r]=X[r]), r= 1..nR)
   od;
   P:= [entries(P, 'pairs')];
   S:-RandomVariable(EmpiricalDistribution(lhs~(P), 'probabilities'= rhs~(P)))
end proc
:  
Dice:= 'St:-RandomVariable(DiscreteUniform(1,6))' $ 2:
Game:= CombineDiscrete([Dice], (x,y)-> piecewise(x=1, -4, y=1, -4, abs(x-y)) ): 
St:-Mean(Game);
                               -1
                               --
                               9 
St:-Variance(Game);
                              620
                              ---
                              81 
St:-Probability(Game=3);
                               1
                               -
                               9
St:-Probability(Game > 2);
                               1
                               -
                               6
seq(St:-Sample(Game, 32));
  1., 2., 1., 3., -4., 2., -4., 2., 2., -4., 0., 1., 0., -4., 1., 
  1., 2., -4., 2., 1., 3., 1., -4., 3., 2., 2., 0., -4., 3., 1., 
  2., 4.
S:= CodeTools:-Usage(St:-Sample(Game, 10^6)):
memory used=15.27MiB, alloc change=15.27MiB, cpu time=47.00ms, real time=55.00ms, gc time=0ns

 

First 149 150 151 152 153 154 155 Last Page 151 of 395