Carl Love

Carl Love

28015 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

a,b,c:= 'RootOf(2012*x^3+2013*x+2014, index= k)' $ k= 1..3:
evala((a+b)^3+(b+c)^3+(c+a)^3);
                              3021
                              ----
                              1006


a:=["0101101","0000101","0001001"];

["0101101", "0000101", "0001001"]

A:= Matrix(length(a[1]), nops(a), (i,j)-> parse(a[j][i]));

A := Matrix(7, 3, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (2, 1) = 1, (2, 2) = 0, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (4, 1) = 1, (4, 2) = 0, (4, 3) = 1, (5, 1) = 1, (5, 2) = 1, (5, 3) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (7, 1) = 1, (7, 2) = 1, (7, 3) = 1})

a||(1..3):= seq(A[..,j], j= 1..3);

a1, a2, a3 := Vector(7, {(1) = 0, (2) = 1, (3) = 0, (4) = 1, (5) = 1, (6) = 0, (7) = 1}), Vector(7, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 1, (6) = 0, (7) = 1}), Vector(7, {(1) = 0, (2) = 0, (3) = 0, (4) = 1, (5) = 0, (6) = 0, (7) = 1})

a1+a2+a3;

Vector(7, {(1) = 0, (2) = 1, (3) = 0, (4) = 2, (5) = 2, (6) = 0, (7) = 3})

 


Download String_to_Matrix.mw

The package is intended to be used in conjunction with Matlab. The name of every procedure in the package is the same as a Matlab command. However, you can use the package on its own, with no connection to Matlab. The main benefit to that (that I can see) is that many of the calling sequences are significantly shorter. For example, MTM:-eig is much less to type than LinearAlgebra:-Eigenvectors.

L:= ["1000","1","1110"]:

map(x-> cat("0" $ 7-length(x), x), L);

Lookup "Shoelace formula" in Wikipedia. This will give the area of any polygon as long as the vertices are given in order (clockwise or counterclockwise).

Area:= proc(P::list([realcons,realcons]))
local k, n:= nops(P);
     abs(add(P[k,1]*P[k+1,2] - P[k+1,1]*P[k][2], k= 1..n-1) + P[n,1]*P[1,2] - P[1,1]*P[n,2])/2
end proc:

Area([[0,0], [10,0], [10,10]]);
                               50

If you want to work within the geometry package, you could do this:

AreaOfTriangle:= proc(P::list([realcons,realcons]))
uses G= geometry;
local A,B,C,ABC;
     G:-area(G:-triangle(ABC, [G:-point(A, P[1][]), G:-point(B, P[2][]), G:-point(C, P[3][])]))
end proc:

AreaOfTriangle([[0,0], [10,0], [10,10]]);
                               50

There is no direct command that I know of, but the computation is trivial. The following procedure returns a sequence of the [center, radius] pairs. Isn't that good enough for you?

Gershgorin:= proc(A::Matrix(square))
local n:= LinearAlgebra:-RowDimension(A), i, j;
     seq([A[i,i], add(abs(A[i,j]), j= 1..n) - abs(A[i,i])], i= 1..n)
end proc:
Gershgorin(LinearAlgebra:-RandomMatrix(4));
          [48, 186], [-12, 149], [-12, 52], [-30, 110]

The LinearAlgebra:-Eigenvectors command returns the matrix P and the diagonal of D.

restart:
macro(LA= LinearAlgebra):
A:= LA:-RandomMatrix(4, datatype= float[8]):
E,P:= LA:-Eigenvectors(A):
Need to make D local because it is reserved for differentiation.
local D:= LA:-DiagonalMatrix(E);
LA:-Norm(P.D.P^(-1) - A);

Essentially 0, but there is some round-off error.

Use the ?Grid package rather than the Threads package. Then there are no worries about "thread safety" because it is not a shared-memory environment. In particular, use ?Grid,Map . Example:

Integrands:= [seq(sin(k*x), k= 1..2^9)]:
Grid:-Map(evalf@Int, Integrands, x= 0..Pi);

Using this, I got 100% processor utilization on my 8-CPU machine.

The output data standarderrors is only available for a linear fit. You can easily convert your problem to a linear one. 

X1:= ln~(X); Y1:= ln~(Y -~ 1);

Now Y1 = ln(a) + b*X1.

Fit(a1+b*n, X1, Y1, n, output= [...]);

Finally a = exp(a1).

Did you have in mind a procedure to plot the circles and the eigenvalues?

restart:

Gershgorin:= proc(M::Matrix(square,complexcons))
uses LA= LinearAlgebra, P= plots;
local A:= evalf(M), n:= LA:-RowDimension(A), i, j;
     P:-display(
          [
               seq(
                    plottools:-circle(
                         [Re,Im](A[i,i]),
                         add(abs(A[i,j]), j= 1..n) - abs(A[i,i]),
                         color= COLOR(HSV, i/n, .5, .5)
                    ),
               i= 1..n
               ),
               P:-pointplot(
                    [Re,Im]~(LA:-Eigenvalues(A)),
                    color= red
               )
          ],
          scaling= constrained,
          symbol= diagonalcross, symbolsize= 16,
          _rest          
     )
end proc:

Example:

macro(LA= LinearAlgebra):

A:= LA:-RandomMatrix(5)+I*LA:-RandomMatrix(5);

A := Matrix(5, 5, {(1, 1) = 29-89*I, (1, 2) = -14+96*I, (1, 3) = 44+34*I, (1, 4) = 11-32*I, (1, 5) = 27-81*I, (2, 1) = 35+95*I, (2, 2) = 37+69*I, (2, 3) = 92-55*I, (2, 4) = 61-9*I, (2, 5) = 58+11*I, (3, 1) = -70+77*I, (3, 2) = -97+72*I, (3, 3) = 73+54*I, (3, 4) = 28+69*I, (3, 5) = 2-76*I, (4, 1) = -43-84*I, (4, 2) = -92+42*I, (4, 3) = -39+79*I, (4, 4) = -48+31*I, (4, 5) = 54+82*I, (5, 1) = -23-63*I, (5, 2) = 73+55*I, (5, 3) = 62-99*I, (5, 4) = -63-66*I, (5, 5) = 47-29*I})

Gershgorin(A);

A:= LA:-RandomMatrix(5) + I*LA:-RandomMatrix(5)+
    7*LA:-DiagonalMatrix(
         LA:-RandomVector(5)+I*LA:-RandomVector(5)
    );

A := Matrix(5, 5, {(1, 1) = 42+32*I, (1, 2) = 82-63*I, (1, 3) = 12+12*I, (1, 4) = 22+21*I, (1, 5) = 60-82*I, (2, 1) = -32+91*I, (2, 2) = 107-453*I, (2, 3) = -62+45*I, (2, 4) = 14+90*I, (2, 5) = -95-70*I, (3, 1) = -1-I, (3, 2) = 42+30*I, (3, 3) = -670-196*I, (3, 4) = 16+80*I, (3, 5) = -20+41*I, (4, 1) = 52+63*I, (4, 2) = 18+10*I, (4, 3) = -68+60*I, (4, 4) = -299-121*I, (4, 5) = -25+91*I, (5, 1) = -13-23*I, (5, 2) = -59+22*I, (5, 3) = -67-35*I, (5, 4) = 99+88*I, (5, 5) = -215-517*I})

Gershgorin(A);

 

 

Download Gershgorin.mw

 

 

You may be able to achieve what you want using the command ?plots,textplot . If you could provide a picture of what you want, I'll try to make it in Maple.

Perhaps you are referring to the tick marks on the axes? It is quite easy to change the position of them. See ?plot,tickmarks .

Don't use capital I as a variable. It is reserved for the imaginary unit. I usually use J instead when I want to use I as a variable.

Don't assign r or d.

Then the algsubs command will work.

What does "y = -0,5+7" mean? Do you mean y= -0.5*x+7? In that case,

plot([2*x-3, -0.5*x+7]);

Here is a not-fully-polished implementation of Muller's method. It will likely fail on multiple roots, and there is no checking for division by zero.

restart:

Muller:= proc(
     f::appliable, inits::[complexcons,complexcons,complexcons],
     {tolerance:= 10.^(1-Digits)}, {maxsteps:= 99}
)
local
     d1, d2, d, b, D, p, k,
     oldDigits:= Digits,
     x0:= inits[1], x1:= inits[2], x2:= inits[3],
     h1:= x1-x0, h2, h,
     fx0, fx1, fx2
 ;
     Digits:= Digits+2+ilog10(Digits);
     fx0:= evalf(f(x0));  fx1:= evalf(f(x1));
     d1:= (fx1-fx0)/h1;
     for k to maxsteps do
          h2:= x2-x1;
          fx2:= evalf(f(x2));
          d2:= (fx2-fx1)/h2;
          d:= (d2-d1)/(h2+h1);
          b:= d2+h2*d;
          D:= evalf(sqrt(b^2-4*fx2*d));
          h:= 2*fx2/(b+`if`(abs(b-D) < abs(b+d), D, -D));
          p:= x2-h;
          userinfo(2, Muller, p);
          if abs(h) < tolerance then
               userinfo(1, Muller, sprintf("Used %d steps", k));  
               return evalf[oldDigits](p)  
          end if;
          x0:= x1;  x1:= x2;  x2:= p;
          fx0:= f(x0);  fx1:= fx2;  fx2:= f(p);
          h1:= h2;  d1:= d2;
     end do;
     FAIL
end proc:
          
infolevel[Muller]:= 2:
Muller(x-> exp(x)+1, [1, 0, -1]);
Muller: -1.08197670686932642-1.58493557680537191*I
Muller: -1.27350123007187934-2.85054027345107362*I
Muller: -.381407414149884648-3.74751157829847389*I
Muller: .197272946056780758-3.14572035519676954*I
Muller: -0.16781896044693894e-1-3.15707732044571707*I
Muller: 0.9078666240418e-6-3.14209510958315899*I
Muller: 0.260490388101188484e-6-3.14159295025712521*I
Muller: -0.80434247308e-13-3.14159265359054070*I
Muller: -0.2472981852860e-18-3.14159265358979324*I
Muller: -0.247298185265482997e-18-3.14159265358979324*I
Muller: Used 10 steps
                         

Check:

evalf(Pi);

                                             3.14159265358979

Compare with fsolve:

fsolve(exp(x)+1, x=-I, complex);
                            

@MOSO1401 Sure, I can help you to make an animation. What do you want to vary? I guess that the above plot represents t=0 and you want to show how the wave evolves over time. Here is the most basic technique:

N:= 20:
for k from 1 to N do
    t:= k*Pi/N;
    frame[k]:= plot3d(sin(x+t)*cos(y+t), x= -Pi..Pi, y= -Pi..Pi)
end do:
plots:-display([seq(frame[k], k= 1..N)], insequence);

First 340 341 342 343 344 345 346 Last Page 342 of 394