Carl Love

Carl Love

28050 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Since your worksheet is long, I stopped reading after I found the first mistake. So, I don't know if this mistake is the ultimate cause of your issue. Correct the mistake, and if you still have your issue, then repost the corrected worksheet, and I'll have another look. (And if you don't still have the issue, please post a followup and say so!)

The mistake is that at one point you mispelled unapply as unpply. It's when you're defining I[Lm2] almost halfway through the worksheet.

You have three problems. The first is a trivial typo. Before the fprintf, you have a "*" which should be a ";". The second is that solve returns multiple solutions, some of which are not real. Your formatting is expecting a single real value. To get a single real value, use fsolve instead of solve (in both cases). The third problem is that with your current settings, each loop is going to execute 3 million times. Do you really want to spend the time required for that? If not, then you either need to reduce the 81920 or increase the value of dtt.


Set all variables to their initial state:

restart:

Define a function...

f:= x-> x^2 + 2*x - 3;

proc (x) options operator, arrow; x^2+2*x-3 end proc

...and its derivative

df:= D(f)(x);

2*x+2

The derivative evaluated at x = 2.

eval(df, x= 2);

6

Another way for the same thing.

D(f)(2);

6

Equation of tangent line at x = 2:

TanLine:= y = f(2) + D(f)(2)*(x - 2);

y = -7+6*x

Plot of the function and the tangent line near the point of tangency.

plot([f(x), eval(y, TanLine)], x= -2..4);

Solve for the derivative being 0.

solve(df = 0, {x});

{x = -1}

 


Download 1stMapleCalcI.mw

The desired expansion is not true for general A and B. (Consider A = B = -1, a = 1/2.) It is necessary to assume that they are positive. The sign of a doesn't matter.

Here are three ways:

expand((A*B)^a) assuming A>0, B>0;

expand((A*B)^a) assuming positive;

simplify((A*B)^a, symbolic);


[Edit: I completely redid this Answer, using all the original variable names, minus the underscores.]

There is a unique solution to your system. To reduce the visual space needed to present the solution, I removed the underscores from all of your names.

 

restart:

for k to 4 do
     e||k:= Vector(4);
     e||k[k]:= 1;
     X||k:= Vector(4, symbol= x||k);
od:

B:= [e1+e4, e2, 0, e1+e4]:

C:= [a,b,c,d]:

for k to 4 do
     eq||k:= add(cat(C[j],k) * X||j, j= 1..4) =~ B[k]
od:

Sol:= solve(
     convert(< eq||(1..4) >, list),
     [seq](seq(x||k[j], j= 1..4), k= 1..4)
):

The solutions all have the same denominator, of course---the determinant of the coefficient matrix. To save space I'll remove the denominators from the solutions.

Numers:= map(lhs=numer@rhs, Sol[]);

[x1[1] = -b1*c2*d3+b1*c3*d2+b2*c1*d3-b2*c3*d1+b2*c3*d4-b2*c4*d3-b3*c1*d2+b3*c2*d1-b3*c2*d4+b3*c4*d2+b4*c2*d3-b4*c3*d2, x1[2] = -b1*c3*d4+b1*c4*d3+b3*c1*d4-b3*c4*d1-b4*c1*d3+b4*c3*d1, x1[3] = 0, x1[4] = -b1*c2*d3+b1*c3*d2+b2*c1*d3-b2*c3*d1+b2*c3*d4-b2*c4*d3-b3*c1*d2+b3*c2*d1-b3*c2*d4+b3*c4*d2+b4*c2*d3-b4*c3*d2, x2[1] = a1*c2*d3-a1*c3*d2-a2*c1*d3+a2*c3*d1-a2*c3*d4+a2*c4*d3+a3*c1*d2-a3*c2*d1+a3*c2*d4-a3*c4*d2-a4*c2*d3+a4*c3*d2, x2[2] = a1*c3*d4-a1*c4*d3-a3*c1*d4+a3*c4*d1+a4*c1*d3-a4*c3*d1, x2[3] = 0, x2[4] = a1*c2*d3-a1*c3*d2-a2*c1*d3+a2*c3*d1-a2*c3*d4+a2*c4*d3+a3*c1*d2-a3*c2*d1+a3*c2*d4-a3*c4*d2-a4*c2*d3+a4*c3*d2, x3[1] = -a1*b2*d3+a1*b3*d2+a2*b1*d3-a2*b3*d1+a2*b3*d4-a2*b4*d3-a3*b1*d2+a3*b2*d1-a3*b2*d4+a3*b4*d2+a4*b2*d3-a4*b3*d2, x3[2] = -a1*b3*d4+a1*b4*d3+a3*b1*d4-a3*b4*d1-a4*b1*d3+a4*b3*d1, x3[3] = 0, x3[4] = -a1*b2*d3+a1*b3*d2+a2*b1*d3-a2*b3*d1+a2*b3*d4-a2*b4*d3-a3*b1*d2+a3*b2*d1-a3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a2*c4*d3+a3*c1*d2-a3*c2*d1+a3*c2*d4-a3*c4*d2-a4*c2*d3+a4*c3*d2, (2) = a1*c3*d4-a1*c4*d3-a3*c1*d4+a3*c4*d1+a4*c1*d3-a4*c3*d1, (3) = 0, (4) = a1*c2*d3-a1*c3*d2-a2*c1*d3+a2*c3*d1-a2*c3*d4+a2*c4*d3+a3*c1*d2-a3*c2*d1+a3*c2*d4-a3*c4*d2-a4*c2*d3+a4*c3*d2})

eval(X3, Numers);

Vector(4, {(1) = -a1*b2*d3+a1*b3*d2+a2*b1*d3-a2*b3*d1+a2*b3*d4-a2*b4*d3-a3*b1*d2+a3*b2*d1-a3*b2*d4+a3*b4*d2+a4*b2*d3-a4*b3*d2, (2) = -a1*b3*d4+a1*b4*d3+a3*b1*d4-a3*b4*d1-a4*b1*d3+a4*b3*d1, (3) = 0, (4) = -a1*b2*d3+a1*b3*d2+a2*b1*d3-a2*b3*d1+a2*b3*d4-a2*b4*d3-a3*b1*d2+a3*b2*d1-a3*b2*d4+a3*b4*d2+a4*b2*d3-a4*b3*d2})

eval(X4, Numers);

Vector(4, {(1) = a1*b2*c3-a1*b3*c2-a2*b1*c3+a2*b3*c1-a2*b3*c4+a2*b4*c3+a3*b1*c2-a3*b2*c1+a3*b2*c4-a3*b4*c2-a4*b2*c3+a4*b3*c2, (2) = a1*b3*c4-a1*b4*c3-a3*b1*c4+a3*b4*c1+a4*b1*c3-a4*b3*c1, (3) = 0, (4) = a1*b2*c3-a1*b3*c2-a2*b1*c3+a2*b3*c1-a2*b3*c4+a2*b4*c3+a3*b1*c2-a3*b2*c1+a3*b2*c4-a3*b4*c2-a4*b2*c3+a4*b3*c2})

 

To be completely rigorous, we need to show that there is at least one assignment of numeric values to the coefficients that makes the denominator non-zero. This is of course trivial to do, and I leave it to you.

Download 16eqns.mw

 

First, you do not need to check the type of x,y,z; they are definitely integer. To find a subset of L with the desired property, we use the combinat package to iterate through subsets of L of size 4. For each subset, we iterate through its subsets of size 3, using geom3d:-IsRightTriangle. The last value of P4 after executing the loop below is your desired group of 4 with no right triangles.

C:= combinat:-firstcomb(nops(L), 4):
while C <> combinat:-lastcomb(nops(L), 4) do
     P4:= L[[C[]]]:
     ct:= 0; #count non rt triangles for this group of 4 pts.
     for P3 in combinat:-choose(P4,3) do
          geom3d:-triangle(
               ABC,
               [seq](geom3d:-point(A||k, P3[k][]), k= 1..3)
          );
          if geom3d:-IsRightTriangle(ABC) then  break  end if;
          ct:= ct+1
     end do;
     # 4 triangles can be made from 4 pts: C(4,3) = 4.
     if ct = 4 then  break  end if;
     C:= combinat:-nextcomb(C, nops(L))
end do:

P4;
      [[-5, 0, 2], [-5, 0, 10], [-4, -2, 3], [-4, -2, 9]]

In your Optimization command (e.g.Minimize, LPSolve) include the option output= solutionmodule:

SM:= Optimization:-Minimize(
     -4*x-5*y,
     {6 >= x+2*y, 20 >= 5*x+4*y, x >= 0, y >= 0},
     output= solutionmodule
):

Now SM is a module, so its contents (aka members) can be accessed with the :- operator. There are two members, SM:-Settings and SM:-Results. What you want is

SM:-Results(iterations);

See ?Optimization,General,Solution

You should forget about the print command. It is the wrong paradigm. It is inhibiting your understanding. Good Maple code very rarely uses it. I say this having read all your previous questions. The better paradigm is to make the result that you want to see the same as the result of the most recently executed command.

The result that you want in the present case can be achieved thus (the linebreak issue is handled automatically by the GUI) :

restart: 
a:= 2:  b:= .29:  d:= 1.85:
eq1:= x*(-b*x^2-x+1):
eq2:= y*((a*x*x)/(b*y^2)-d-h*y):
h:= .5: for k while 1 >= h do
     h:= h + .1;     
     S:= solve({eq1, eq2}, {x, y});
     X[k],Y[k]:= eval([x,y], S[2])[]
end do:
convert(X, list); convert(Y,list);

   [0.809816975292943, 0.809816975292943, 0.809816975292943,
   0.809816975292943, 0.809816975292943, 0.809816975292943]

    [1.30989205371406, 1.28289831180836, 1.25827763787148,
1.23567070473363, 1.21479304855971, 1.19541568678247]

You may have an old worksheet. If you have the 32-bit version of Maple, then you have the Classic interface. Use that to open the worksheet. Then resave it. Then try again with Standard. If you have 64-bit, then post the worksheet, and I'll do it for you.

Two (of many) ways:

A:= t-> [a(t), b(t), c(t)]; #a list

A:= t->  < a(t), b(t), c(t) >; #a (column) vector

To prove that two algebraic numbers A and B are equal, use

evala(Normal(A-B));

You will get 0 if and only if they are equal.

In your case, they are equal. In this case simplify(A-B) will also work; however, the evala technique is guaranteed to work whereas the simplify is not.

The question remains, How can the first form be simplified to something like the second form? One technique that works in this case is identify.

r:= evalf(A):
for d from Digits+1 to 2^13 while r::float do
     r:= identify(evalf[d](A));
end do:
d-1, r;

This is only a guess (albeit a very sophisticated guess), and it still needs to be proven:

eval(Normal(A-r));

                               0
 

Here is a version that I've reworked to make use of parallel processing. I needed to increase the number of side vectors b to 2^12 in order to get a meaningful time measurement. If your number of side vectors is only about 100 (like you said), it will be extremely wasteful to use the code below. This is because the overhead involved in setting up the parallel processing will be far greater than the time to solve the problem on one processor.


restart:

The float[8] technique used in this worksheet is extremely fast and is limited to moduli less than 2^25. If you need a larger modulus, it is very easy to modify (let me know), and  just a little slower.

N:= 2^7:  #order of matrix A
n:= 2^12:  #number of vectors b[i]
p:= 127:  #prime modulus

isprime(p);

true

Generate a random example upper triangular nonsingular A.

A:= LinearAlgebra:-RandomMatrix(
     N, shape= triangular[upper, unit], datatype= float[8]
):

Convert to shape= rectangular, which is required by LinearAlgebra:-Modular.

A:= Matrix(A, shape= rectangular):

Input A to the Modular system.

A:= LinearAlgebra:-Modular:-Mod(p, A, float[8]):

 

Generate a list of random side vectors b[k].

b:= [seq](
     LinearAlgebra:-RandomVector(N, datatype= float[8]),
     k= 1..n
):

Make a solving procedure that can be mapped into parallel processors. It returns the solution for a single side vector.

Solve:= proc(b::Vector, A::Matrix, p::posint)
     uses LAM= LinearAlgebra:-Modular;
     local B:= LAM:-Mod(p, b, float[8]);
     LAM:-BackwardSubstitute(p, A, B);
     B
end proc:     

 

For reasons that I don't understand, it seems necessary to make a single bogus call to LinearAlgebra:-Modular:-BackwardSubstitute and generate an error before the parallel version will work. This only seems to be necessary once after each restart.

LinearAlgebra:-Modular:-BackwardSubstitute(p);

Error, (in LinearAlgebra:-Modular:-BackwardSubstitute) incorrect number of arguments

 

Threads:-Map is a parallel processing version of map. All that you need to run the parallel code is...

# X:= Threads:-Map(Solve, b, A, p);

...the rest of the code in the command below is just there to measure the time.

CodeTools:-Usage(
     proc() :-X:= Threads:-Map(Solve, b, A, p) end proc()
):

memory used=5.30MiB, alloc change=15.31MiB, cpu time=234.00ms, real time=36.00ms

It looks like the code parallelizes extremely well:

36.*kernelopts(numcpus)/234.;

1.23076923076923

It's actually the best parallelization ratio that I've ever achieved in my own code.

But if you compare the time with the single-processor time for the same number of b's, you will see that there is no savings using the parallel code. You would have to use about 2^16  b's before there would be any savings.

 

Verify results (not really necessary):

for k to n do
     if LinearAlgebra:-Norm(
             LinearAlgebra:-Modular:-AddMultiple(
                  p,
                  p-1,
                  LinearAlgebra:-Modular:-Multiply(p, A, X[k]),
                  LinearAlgebra:-Modular:-Mod(p, b[k], float[8])
             )
        )
        <> 0
     then error "Bad solve"
     end if
end do;
"All solutions check";

"All solutions check"

 


Download ParallelModular.mw

 

At the sizes that you are talking about, it is not worth using multiple parallel processors. The following solution command runs in time less than the smallest time that can be measured directly by Maple, which is 1/64 seconds. If you really want to run on multiple parallel processors, let me know. But I think that the overhead of initiating the processes would outweigh any time savings.

Here's an example.

 

restart:

The float[8] technique used in this worksheet is extremely fast and is limited to moduli less than 2^25. If you need a larger modulus, it is very easy to modify (let me know), and  just a little slower.

N:= 2^7:  #order of matrix A
n:= 2^6:  #number of vectors b[i]
p:= 127:  #prime modulus

isprime(p);

true

Generate a random example upper triangular nonsingular A.

A:= LinearAlgebra:-RandomMatrix(
         N, shape= triangular[upper, unit], datatype= float[8]
    ):

Convert to shape= rectangular, which is required by LinearAlgebra:-Modular.

A:= Matrix(A, shape= rectangular):

Input A to the Modular system.

A:= LinearAlgebra:-Modular:-Mod(p, A, float[8]):

 

Generate a list of random side vectors b[k].

b:= [seq](LinearAlgebra:-RandomVector(N, datatype= float[8]),
         k= 1..n
    ):

Combine all the vectors into one matrix.

B:= `<|>`(seq(b[k], k= 1..n)):

Input it to Modular.

B:= LinearAlgebra:-Modular:-Mod(p, B, float[8]):

 

LinearAlgebra:-Modular:-BackwardsSubstitute does not "return" the answer. Rather, it overwrites B with the answer. In order to save B, we need to copy it.

X:= LinearAlgebra:-Modular:-Copy(p, B):

Solve system AX=B.

LinearAlgebra:-Modular:-BackwardSubstitute(p, A, X);

 

Verify results (not really necessary):

for k to n do
     if LinearAlgebra:-Norm(
             LinearAlgebra:-Modular:-Multiply(p, A, X[.., k])
             - B[.., k]
        )
        <> 0
     then error "Bad solve"
     end if
end do;
"All solutions check";

The kth solution vector can be extracted thus:

k:= 9:

X9:= X[.., k];

X9 := Vector(4, {(1) = ` 1 .. 128 `*Vector[column], (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

(Optional) Convert back to true integer form.

X9int:= map(trunc,X9);

X9int := Vector(4, {(1) = ` 1 .. 128 `*Vector[column], (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*C_order})

X9int[37], X9[37];

121, HFloat(121.0)

 

 

Download ModularSolve.mw

It can be done with a single plot command. No transform or display is needed.

restart:
V:= exp(-x)*y^3/eta^3:
eta:= 1+k*x+sin(2*Pi*x):
x:= 0.1:
Ks:= [.1, .5, -.1]:
plot(
     [seq](eval([V, y, y= 0..eta], k= K), K= Ks),
     labels= ["v", "y"],
     color= [black, red, blue],
     linestyle= [solid, dash, dot],
     legend= [seq](k = K, K= Ks)
);

It is sad that you have not received more help.... I can give you a tiny bit of help, but I have very little knowledge of this subject area. I think that some of what you want can be done with the ?DynamicSystems package. In particular, there is ?DynamicSystems,BodePlot and ?DynamicSystems,TransferFunction .

I think that Joe Riel may know this package well. Maybe he will notice this namecheck and respond.

Also, could you please retype your expressions in normal characters? The Maple Math typesetting is horrible---nearly impossible to read.

First 363 364 365 366 367 368 369 Last Page 365 of 395