Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love


restart:

Pts:= [[2,0], [6,1], [8,0]]:

n:= nops(Pts):

V:= [a, b, c]:

f:= unapply(add(V[k]*x^(n-k), k= 1..n), x);

proc (x) options operator, arrow; a*x^2+b*x+c end proc

Eqns:= (p-> f(p[1]) = p[2]) ~ (Pts);

[4*a+2*b+c = 0, 36*a+6*b+c = 1, 64*a+8*b+c = 0]

A:= LinearAlgebra:-GenerateMatrix(Eqns, V, augmented);

A := Matrix(3, 4, {(1, 1) = 4, (1, 2) = 2, (1, 3) = 1, (1, 4) = 0, (2, 1) = 36, (2, 2) = 6, (2, 3) = 1, (2, 4) = 1, (3, 1) = 64, (3, 2) = 8, (3, 3) = 1, (3, 4) = 0})

R:= LinearAlgebra:-ReducedRowEchelonForm(A);

R := Matrix(3, 4, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = -1/8, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (2, 4) = 5/4, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = -2})

Sol:= convert(V =~ R[..,-1], list);

[a = -1/8, b = 5/4, c = -2]

eval(f(x), Sol);

-(1/8)*x^2+(5/4)*x-2

 


Download Interpolate.mw

I used exact arithmetic in your worksheet, and I got all zeros at the end. To use exact arithmetic, I did three things:

  1. I changed all numbers of the form 210e9 to 210*10^9
  2. I changed all numbers of the form 0.5, 0.25, etc., to 1/2, 1/4, etc.
  3. I removed all evalf.

Luckily, there was no significant increase in the computation time. With these changes, the setting of Digits is insignificant.

Here is the modified worksheet: Exact_arithmetic.mws

 

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]);

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