dharr

Dr. David Harrington

8205 Reputation

22 Badges

20 years, 338 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are answers submitted by dharr

Well, this finds any of the polynomials. But what type of answer exactly is expected here?

restart

eq := (-x^2+x)^(4*n) = (x^2+1)*p+(-4)^n

(-x^2+x)^(4*n) = (x^2+1)*p+(-4)^n

p := solve(eq, p)

-((-4)^n-(-x^2+x)^(4*n))/(x^2+1)

p7 := normal(eval(p, n = 7), expanded)

x^54-28*x^53+377*x^52-3248*x^51+20098*x^50-95032*x^49+356642*x^48-1089008*x^47+2751463*x^46-5817892*x^45+10371647*x^44-15656288*x^43+20050108*x^42-21785872*x^41+20066492*x^40-15656288*x^39+10355263*x^38-5817892*x^37+2767847*x^36-1089008*x^35+340258*x^34-95032*x^33+36482*x^32-3248*x^31-16007*x^30-28*x^29+16385*x^28-16384*x^26+16384*x^24-16384*x^22+16384*x^20-16384*x^18+16384*x^16-16384*x^14+16384*x^12-16384*x^10+16384*x^8-16384*x^6+16384*x^4-16384*x^2+16384

NULL

Download polynomial.mw

use sol:-value(r=0..10,t=0..20) to get the values out. [Edit - not correct - see correct answer below] (It is helpful if you load your actual worksheet using the big green up-arrow in the Mapleprimes editor.)

The error is because C1 is zero. My recollection is that the calculation of the t-value involves dividing by the standard error, which is zero. Then the absolute value of infinity leads to the complex infinity.

You should scale your dependent data down to values within a few orders of magnitude of 1, say by dividing it by 10^7. Then your parameters will be 10^7 times higher and more reasonable. You are likely running into numerical accuracy issues because your problem is not better scaled. Actually you could use stronger scaling for the last column.

Here is a scaled version that works:

toycode3.mw

with(GraphTheory);
G := Multigraph(2, [{1, 2}, {1, 2}]);
DrawGraph(G);

The 2 by the edge in DrawGraph shows there are two edges between vertices 1 and 2.

You can have several worksheets open with the same Maple engine - See Tools->Options->General tab, and under Mathematical Engine choose "Share one engine among all documents".

Alternatively you can save variables with the save command, and then use the read command to retrieve them.

Conversion to arbitrary real base > 1. Adapted from  https://en.wikipedia.org/wiki/Non-integer_base_of_numeration

restart;

This version for each digit < "Z". Output is string. precision is number of digits after the point.

conv:=proc(number,base,precision::posint)
  local k,result,i,digit,n,b,q,alphabet,sign;
  alphabet:="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  n:=evalf(number);
  sign:=signum(n);
  if sign = 0 then return "0" end if;
  b:=evalf(base);
  if b<=1 then error "base must be >1" end if;
  if floor(b)>length(alphabet) then error "base too large for alphabet" end if;
  k := floor(log[b](sign*n)) + 1;
  Digits:=k+precision+5;
  n:=evalf(sign*number);
  b:=evalf(base);
  k := floor(log[b](n)) + 1;
  result := "";
  for i from k-1 by -1 while i > -precision-1 do
    q:=n/b^i;
    digit:=floor(q-b*floor(q/b));
    n:=n-digit*b^i;
    result:=cat(result,alphabet[digit+1]);
  end do;
  if k>0 then
    result:=cat(result[1..k],".",result[k+1..-1])
  else
    result:=cat("0.",StringTools:-Fill("0",-k),result)
  end if;
  if sign=1 then
    result
  else
    cat("-",result)
  end if;
end proc:

Examples

conv(exp(1), sqrt(5), 60);

"10.100012001101002001020001000120011120012010000011102001001111"

conv(-27, Pi, 60);

"-220.300202001222002022021123003002220111200220220010221021011111"

NULL

Download tobase.mw

In general there are many roots. An implicitplot will show curves where there are solutions. The algcurves packsge has more routines to analyse such curves.

restart

P := randpoly([x, y])

-92*x^3*y^2+6*x^2*y^3+74*x*y^4+23*x^4+75*x*y^3-50*x

plots:-implicitplot(P, x = -5 .. 5, y = -5 .. 5)

algcurves also show an isolated solution at the origin

algcurves:-plot_real_curve(P, x, y)

algcurves:-singularities(P, x, y); evalf(%)

{[[0, -RootOf(74*_Z^4-75*_Z^3-50), 1], 2, 1, 2]}

{[[0., -1.312413632, 1.], 2., 1., 2.]}

NULL

Download bivariate.mw

Here I use @acer's routine and color the digits according to HUE: 0..1 maps to 0..16777215.
Don't know how to do the more general case with non-integer bases.

[Edit: forgot the decimal point - now fixed]

1024 digits of exp(1) in base 256^3 = 16777216

restart;

@acer's routine from Mapleprimes here without the conversion to a string

F:=proc(x,b::posint,N::posint)
 local y,p:
 y:=ListTools:-Reverse(
   convert(floor(evalf[floor(N*ln(b)/ln(10))](x*b^N)),base,b)):
 p:=nops(y)-N; #point after first p "digits"
 #cat(op(y[1..p]),".",op(y[p+1..N]));
 b,p,y
 end proc:

Routine to plot this in colors according to HUE

plotnumber:=proc(b,p,num)
  local rows,cols,N,M,p1,p2,pp;
  cols:=32;
  N:=nops(num)-1;
  rows:=ceil(N/cols);
  M:=Matrix(rows,cols,evalf(num[1..-2]/~(b-1)));
  # list density plot order needs transpose then reverse rows
  pp:=[p mod cols+0.5,rows-iquo(p,rows)];
  p1:=plots:-listdensityplot(ArrayTools:-FlipDimension(M^%T,2),
         colorstyle=HUE,scaling=constrained,axes=none);
  p2:=plots:-pointplot(pp,symbol=solidcircle,symbolsize=12,color=black,axes=none);
  plots:-display(p1,p2);
end proc:

b,p,num:=F(exp(1),256^3,1024):

plotnumber(b,p,num);

NULL

Download expcolors.mw

ctrl-k inserts a new execution group before the current one; ctrl-j after the current one (cmd-j,cmd-k on Mac). There is also the >_ icon on the toolbar that inserts after the current execution group. I'm assuming worksheet mode; for document mode to get new input but not a new prompt it is ctrl-shift-k etc.

You could use string manipulations to automate a file conversion for the simple stuff as in the example file below, and then hand edit the file for the things that don't easily convert. (integrate is a synonym for int, so you could leave that). Of course you could spend a lot of time on a more sophisticated conversion process, but I'm guessing it is easier to do an approximate conversion and then fix things up in Maple. I "read" the modified file in the example, which means that Maple parses the commands, but it might be easier to copy from the converted file to an input region.

MaxToMaple.mw

Spelling error

wiht(LinearAlgebra) should be with(LinearAlgebra)

There is no general formula in terms of radicals for a general 5th degree polynomial. For some cases of coefficients there will be solutions, roots(x^5-1); is a simple example.

As @Carl Love says, walks are enumerated by the adjacency matrix, and can be used to do this.

restart

with(GraphTheory); with(LinearAlgebra)

G := AddVertex(PathGraph(5), [6, 7]); AddEdge(G, {{3, 7}, {4, 6}, {6, 7}}); DrawGraph(G, layout = circle, size = [250, 250])

GRAPHLN(undirected, unweighted, [1, 2, 3, 4, 5, 6, 7], Array(1..7, {(1) = {2}, (2) = {1, 3}, (3) = {2, 4}, (4) = {3, 5}, (5) = {4}, (6) = {}, (7) = {}}), `GRAPHLN/table/2`, 0)

n := NumberOfVertices(G)

7

A := AdjacencyMatrix(G)

B := `~`[`*`](A, Matrix(n, n, symbol = omega))

Matrix(%id = 36893490081594197644)

B^2 enumerates all walks of length 2. Look at the diagonals to find the ones that return. So for example from vertex 3 back to 3 there are three such walks, and the omegas tell where we went.

R := Diagonal(B^2)

Vector[column](%id = 36893490081591008900)

So if we collect the indices in each term into a set, we can see when we have a set of all vertices. Here after 8 steps we aren't done yet for vertex 1.

makesets:=y->evalindets(evalindets[2](expand(y),`^`,1,op),`*`,x->map(u->`if`(type(u,integer),NULL,op(u)),{op(x)})):

a:=(B^8)[1,1];
makesets(a);

(omega[1, 2]^2*omega[2, 1]^2+omega[1, 2]*omega[2, 1]*omega[2, 3]*omega[3, 2])^2+(omega[1, 2]^2*omega[2, 1]*omega[2, 3]+omega[1, 2]*omega[2, 3]*(omega[2, 3]*omega[3, 2]+omega[3, 4]*omega[4, 3]+omega[3, 7]*omega[7, 3]))*(omega[3, 2]*omega[2, 1]^2*omega[1, 2]+(omega[2, 3]*omega[3, 2]+omega[3, 4]*omega[4, 3]+omega[3, 7]*omega[7, 3])*omega[3, 2]*omega[2, 1])+omega[1, 2]*omega[2, 3]*omega[3, 4]*omega[4, 5]*omega[5, 4]*omega[4, 3]*omega[3, 2]*omega[2, 1]+omega[1, 2]*omega[2, 3]*(omega[3, 4]*omega[4, 6]+omega[3, 7]*omega[7, 6])*(omega[4, 3]*omega[6, 4]+omega[6, 7]*omega[7, 3])*omega[3, 2]*omega[2, 1]

{1, 2, 3, 4, 7}+{1, 2, 3, 4, 5}+{1, 2, 3, 4, 6}+2*{1, 2, 3, 4, 6, 7}+{1, 2, 3, 6, 7}+{1, 2, 3, 4}+{1, 2, 3, 7}+{1, 2, 3}+{1, 2}

So here is a procedure for finding the length of the shortest returning walk. For a directed graph it might not terminate.

WalkLength:=proc(G::Graph,v)
  uses GraphTheory;
  local x,y,u,vv,A,B,makesets,n,vertset,i,omega;
  if not member(v,Vertices(G),'vv') then error "vertex not in graph" end if;
  if not IsConnected(G) then return infinity end if;
  makesets:=y->evalindets(evalindets[2](expand(y),`^`,1,op),
                      `*`,x->map(u->`if`(type(u,integer),NULL,op(u)),{op(x)})):
  n:=NumberOfVertices(G);
  vertset:={$(1..n)};
  A:=AdjacencyMatrix(G)*~Matrix(n,n,symbol=omega);
  B:=copy(A);
  for i from 2 do
    B:=B.A;
  until has(makesets(B[vv,vv]),[vertset]);
  i;
end proc:

WalkLength(G, 1)

10

NULL

Download Walks3.mw

 

I think this is fairly robust.

get_exponent:=(expr,x::name)->diff(expr,x)/expr*x:
get_exponent(x^2,x);
get_exponent(x^(n-1),x);
get_exponent(3*x^(n+2),x);
get_exponent(3*x[2]^k*x[3]^(n+2),x[3]);

    
                               2

                             n - 1

                             n + 2

                             n + 2

Once you entered floating point values in your Matrix, the implication is that you have given up on symbolic solutions. Since the Matrix wasn't obviously of a structure that has real eigenvalues, the algorithm used was a general one that generated complex values. As @acer pointed out, you can then make them look nicer, but the algorithm used is the same. For a symmetric Matrix, if you use shape=symmetric, then Maple will choose an algorithm that will produce real eigenvalues and eigenvectors (try it on A:=Matrix(2,2,[[0.8,0.3],[0.3,0.7]],shape=symmetric);).

But if you enter exact values in the first place, then Maple will do the whole calculation exactly. In general, this is the power of Maple over a regular programming language. Here I converted the values you entered to rationals to avoid re-entering, but you could have entered these directly.

Download Eigenvectors.mw

First 31 32 33 34 35 36 37 Last Page 33 of 81