Carl Love

Carl Love

25796 Reputation

25 Badges

10 years, 348 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Change product to mul in your expression. The commands add, mul, and seq are alike in that they don't evaluate their arguments until the index values are substituted; whereas their analogs sum, product, and $ act like the vast majority of Maple commands by evaluating their arguments before they are even passed to the command. In your case, the attempt to evaluate k[j], etc., before j has been assigned a value causes the error.


UnionClosure:= proc(T::set(set))
local R,Iter,k,T1;
     #Next line doesn't change the output, but potentially reduces iterations by a factor of 4.
     T1:= T minus {`union`(T[]), {}};
    Iter:= combinat:-subsets(T1);
     for k while not Iter['finished'] do R[k]:= `union`(Iter['nextvalue']()[]) end do;
    {entries}(R, 'nolist')
end proc:

Example:
UnionClosure({{1},{1,2},{3}});
           {{}, {1}, {3}, {1, 2}, {1, 3}, {1, 2, 3}}

In order for your operation to be well defined, there can be no repeats among the first elements within each list of ordered pairs. Given that, here's an example of how to do your operation. We convert the lists to tables, add the tables (essentially), and convert the result back into a list of ordered pairs.

 

restart;

with(RandomTools,Generate):

Generate two lists of distinct random numbers that will be the first elements of the ordered pairs.

(X1,X2):= '[{Generate(list(posint(range= 9), 9))[]}[]]' $ 2;

[1, 2, 4, 5, 6, 7, 8], [2, 3, 4, 8, 9]

Generate lists of second elements.

(Y1,Y2):= 'Generate(list(posint(range= 9), nops(X||k)))' $ k= 1..2;

[1, 6, 7, 7, 3, 3, 5], [3, 8, 3, 1, 1]

Form the two lists of ordered pairs.

(L1,L2):= 'zip(`[]`, X||k, Y||k)' $ k= 1..2;  

[[1, 1], [2, 6], [4, 7], [5, 7], [6, 3], [7, 3], [8, 5]], [[2, 3], [3, 8], [4, 3], [8, 1], [9, 1]]

Convert them to tables.

(T1,T2):= 'table(map(`=`@op, L||k))' $ k= 1..2:

 

Perform the desired adding operation, storing the results in a third table.

for x in indices(T1, nolist) do
     if assigned(T2[x]) then  T3[x]:= T1[x]+T2[x]  end if
end do;

Convert the resulting table into a list of ordered pairs

map([lhs,rhs], op(2,op(T3)));

[[2, 9], [4, 10], [8, 6]]

 

Download ListTableList.mw

You have entered the following equation with mod:

As far as I know, there is no provision in Maple for non-integer moduli. (I hope that someone will correct me if I am wrong about that or confirm that I am right.) Maple allows you to enter the expression because it is symbolic, and thus there's a chance that the expression will become integer when values are supplied for w and v. But that's not going to happen here. The above equation causes lengthy modp expressions to be carried through your computation. This is not the direct cause of your fsolve error, but after you correct the situation pointed out by Preben, you will eventually get an error because of the mod.

Your attached file is missing. But attemping to answer anyway, I get the different series:

series(exp(1/z), z=1);
                          3               2   13               3
exp(1) - exp(1) (z - 1) + - exp(1) (z - 1)  - -- exp(1) (z - 1)
                          2                   6                 

     73               4   167               5    /       6\
   + -- exp(1) (z - 1)  - --- exp(1) (z - 1)  + O\(z - 1) /
     24                   40                               

series(exp(z), z=1);

                          1               2   1               3
exp(1) + exp(1) (z - 1) + - exp(1) (z - 1)  + - exp(1) (z - 1)
                          2                   6                

     1                4    1                5    /       6\
   + -- exp(1) (z - 1)  + --- exp(1) (z - 1)  + O\(z - 1) /
     24                   120                              


The data matrix for most simple plots p (including the ones here) is op([1,1], p). We can take both the x and y coordinates from the first plot and take just the y coordinate column ([..,2]) from the other two. We paste the columns together with the Matrix constructor `<|>` (which is not often used in this prefix form). Putting that all together, we get the 50 x 4 Matrix via

M:= `<|>`(op([1,1], p1), map(p-> op([1,1], p)[..,2]^%T, [p2,p3])[]);

Then you can right click on it and select Export, or use ExportMatrix(...).

Note that if you use 50 points on the interval 0..1, then the spacing is 1/49, so you're not going to get nice round x values like you show in your example.

Did you mean p(max(m)) = max(n) rather than what you wrote, p(max(m)) = p(max(n))? If so, this will work:

m:= [$0..5]:  n:= [$0..9]:
M:= nops(m):  N:= nops(n):
R:= rand(N):
p:= table(m =~ [0, sort(['R()' $ M-2])[], n[-1]]);

Like this

Sum(Sum(A[i2]*A[n-i2], i2= 0..n)*
    Sum(u[j]*Sum(u[r]*u[m-1-n-j-r], r= 0..m-1-n-j), j= 0..m-1-n),
n= 0..m-1);

Ordinary division by `/` is overloaded to work correctly with mod:

s= 2503/2275 mod 1563;
                            s = 976

For your other question, put the equation just as you have it into isolve:

isolve(s = (940+1563*k)/2275);
           {k = 1420 + 2275 _Z1, s = 976 + 1563 _Z1}

Maple's Matrices and multi-dimensional Arrays should be indexed SOM[i,j]. Your second attempt didn't work because you had SOM[i][j]. This latter style of indexing will work sometimes, such as when accessing the value, but it won't work for an Array or Matrix element on the left side of the assignment operator (:=). Unfortunately, it doesn't produce an error message either.

Your first attempt didn't work because your initializer wasn't a procedure. Markiyan's answer shows how to correct that.

You can use the regular plot command to plot any procedure that takes a real numeric argument and returns a real numeric value. The procedure could encapsulate your fsolve call. Like this:

f:= proc(x)
   local y;
   fsolve(sin(y)=x, y= -Pi/2..Pi/2)
end proc:

plot(f, -0.9..0.9);

Here are some mistakes that I found:

  1. You define a g (you called it "the function to iterate"), but I can't see that you ever use it.
  2. You assign a plot to IP, but later on you use IP as if it were a list of points.
  3. You define a list of points Initial, but I can't see that you ever use it.
  4. You define CylPts as a function; it should be that function mapped over the list of points SortedPts.
  5. The parameter of CylPts should be P, not IP.
  6. ErrR and ErrZ should have n points, not n+1.
  7. In the last line, you use a variable InitialPlot whose value was never assigned.

The big error is 2. I recommend that while you are writing code, you should not end lines with a colon. If you had been watching the output of your commands, you would've spotted error 2 much sooner.

 

Good work so far.

(ii) The concentration is just the amount of salt divided by the volume of the tank. The volume is constant at 100 liters. The amount is your answer to (i).

(iii) "Steady state" just means the limit as time t goes to infinity. The answer to that is probably obvious to you. But you can get it in Maple via limit(sol, t= infinity);

(iv) Part (iv) is to part (iii) as part (ii) is to part (i). Understand?

In fact, Maple's square roots are the principal values, and thus Maple's square roots of positive values are always positive. The situation that you describe arises simply because Maple chooses not to do the simplification automatically. But you tell Maple to do it with combine.

sqrt(6) - sqrt(2)*sqrt(3);
                      (1/2)    (1/2)  (1/2)
                     6      - 2      3     

combine(%);

                               0

sqrt(2)*sqrt(3)*sqrt(5)*sqrt(7);

                   (1/2)  (1/2)  (1/2)  (1/2)
                  2      3      5      7     

combine(%);

                               (1/2)
                            210     

Your expression can be entered as sin(x)^3 or (sin^3)(x), but sin^3(x) will not work. Once the expression is entered, you can use the command combine. That might seem like a strange name for this operation, but this is just a special case.

ex:= (sin^3)(x);
                                  3
                            sin(x)
combine(%);
                      1            3       
                    - - sin(3 x) + - sin(x)
                      4            4       


First 350 351 352 353 354 355 356 Last Page 352 of 374