maplefan123

35 Reputation

4 Badges

3 years, 344 days

MaplePrimes Activity


These are questions asked by maplefan123

I have the following code. I want to do the modify it so that:

1. The outputs of each for loop are merged in such a way that the outputs from the first loop (Es) that are also outputs of the second loop (Fs) are removed from the outputs of (Es).

2. The resulting outputs G= .... are saved to a text file, one to each line.

3. In between each output, I want to add 5 lines of text and a blank line, say

text1 text2 text3

text2 text2 text3

text3 text3 text3

text4 text4 text4

text5 text5 text5

(blank line)

so that in the text file, the format is (e.g.)

G={{1,2}};

text1 text2 text3

text2 text2 text3

text3 text3 text3

text4 text4 text4

text5 text5 text5

(blank line)

G={{1,2},{1,3}};

text1 text2 text3

text2 text2 text3

text3 text3 text3

text4 text4 text4

text5 text5 text5

(blank line)

etc.

What is the easiest way to accomplish this?

restart;
 
with(GraphTheory):
 n:= 4:
  L:= NonIsomorphicGraphs
      ( n,
        output=iterator,
        outputform=graph):
  Es:= Array
       ( [ seq
           (  Edges( L() ),
              j=1..NonIsomorphicGraphs
                   ( n,
                     output=count
                   )
           )
         ]
       ):


  M:= NonIsomorphicGraphs
      ( n-1,
        output=iterator,
        outputform=graph):
  Fs:= Array
       ( [ seq
           (  Edges( M() ),
              j=1..NonIsomorphicGraphs
                   ( n-1,
                     output=count
                   )
           )
         ]
       ):
;

numelems(Es): 
for i from 1 to numelems(Es) do G:=Es[i]:  od;
                           
numelems(Fs):
for i to numelems(Fs) do G := Fs[i]; od;
                        

Is there an easy command to generate the edge sets of of all connected graphs for a given number of vertices? Ideally, I'd like to output to be of the form (e.g.)

G={{1,2},{2,3},{1,3},{1,4}};

text text text text;

text1 text1;

so that I can easily copy it into another program to be read. Or, is there a way that I can produce an output like the following (e.g. for n=3)

G={{1,2},{2,3}};

text text text text;

text1 text1;

G={{1,2},{2,3},{1,3}};

text text text text;

text1 text1;

and have it export to a text file?

B(4) := x^4 - 4*x^3/(2 + p) - 6*(p - 1)*x^2/((3 + p)*(2 + p)) - 4*p*(p - 5)*x/((4 + p)*(3 + p)*(2 + p)) - (p - 1)*(p^2 - 15*p - 4)/((5 + p)*(4 + p)*(3 + p)*(2 + p));
for p from -1 to 5000 do
    A(p) := fsolve(B(4), x, ':-complex');
end do;
Error, (in fsolve) p is in the equation, and is not solved for
ptlist := [0];
for j from -1 to 5000 do
    ptlist := [op(ptlist), A(j)];
end do;
with(plots);
complexplot(ptlist, x = -1 .. 1.5, y = -0.5 .. 0.5, style = point);


I get an error with this code, but when I replace B(4) with its assignment in fsovle, it works. Why is this, and is there a way I can write B(4) instead of the longer expression x^4 - 4*x^3/(2 + p) - 6*(p - 1)*x^2/((3 + p)*(2 + p)) - 4*p*(p - 5)*x/((4 + p)*(3 + p)*(2 + p)) - (p - 1)*(p^2 - 15*p - 4)/((5 + p)*(4 + p)*(3 + p)*(2 + p)) in the fsolve argument?

I have the following polynomials, and I want to multiply each term of the polynomial by the least common denomiator, so that the denominators are cleared. However, I want to keep the products and powers of terms together. So for example, B(2) should become (2+p)(3+p)x^2-2(3+p)x-p-1.

How can I accomplish this? Alternatively, given the following polynomials, I want to factor only the expressions of p in the brackets, so we have (2+p), (2+p)(3+p), etc.

Page 1 of 1