Jean-Claude Arbaut

Mr. Jean-Claude Arbaut

72 Reputation

One Badge

3 years, 338 days
I used briefly Maple in the late 90s during my undergraduate studies. Back then it was Maple V r4 if I remember correctly, and a few years later Maple 6. I use again Maple since around 2018.

MaplePrimes Activity


These are questions asked by Jean-Claude Arbaut

Here is what I'm trying to do. Say I have a Digraph G1 defined by:

with(GraphTheory):
G1:=Digraph([a,b,c],{[[a,b],2],[[b,c],3],[[c,a],4]});

I would like to produce the undirected graph G2, with the same weights:

G2:=Graph([a,b,c],{[{a,b},2],[{b,c},3],[{c,a},4]});

After looking in the GraphTheory package, I found UnderlyingGraph, which seems to do what I want.

Namely,

G3:=UnderlyingGraph(G1,weighted=true);

I had a first problem: there is a bug in the documentation, as the option is 'weights' in the documentation, whereas the source code shows it must be 'weighted'.

 

But then I had another problem, but maybe I didn't understand the purpose of UnderlyingGraph: apparently, I don't get G2. For instance:

 

DijkstrasAlgorithm(G1,a);
            [[[a], 0], [[a, b], 2], [[a, b, c], 5]]

DijkstrasAlgorithm(G2,a);
              [[[a], 0], [[a, b], 2], [[a, c], 4]]

DijkstrasAlgorithm(G3,a);
            [[[a], 0], [[a, c, b], 0], [[a, c], 0]]

The problem seems to come from the weight matrix, which is not symmetric (it is for G2):

WeightMatrix(G3);
                           [0  2  0]
                           [       ]
                           [0  0  3]
                           [       ]
                           [4  0  0]

Edges(G3,weights=true);

{[{a, b}, 0], [{a, b}, 2], [{a, c}, 0], [{a, c}, 4], [{b, c}, 0], [{b, c}, 3]}

 

However, G3 is undirected:

IsDirected(G3);

          false

So, the graph is undirected, but it has different weights for a-b and b-a. Weird.

Now, I am wondering what UnderlyingGraph is supposed to return. After looking at the source code, it seems the statement EW := EW0 + LinearAlgebra:-Transpose(EW0) builds a symmetric weight matrix, but for some reason it's not what is returned.

Is this a bug in the function? Or did I do something wrong? Is there a better way to achieve what I wanted?

 

Is there a way to tell Maple to compute an integral over a domain defined by an implicit condition?

A trivial example would be: integrate 1 over the 2D domain defined by x^2+y^2<=1.

I know it's possible to write the explicit double integral

int(int(1,y=-sqrt(1-x^2)..sqrt(1-x^2)),x=-1..1);

Or even as a single integral:

integrate(2*sqrt(1-x^2),x=-1..1);

However, it's not always possible to do this explicitly, depending on the form of the relation f(x,y)=0 defining the domain.

 

My idea was:

int(Heaviside(1-x^2-y^2),[x=-1..1,y=-1..1]);

But Maple returns 0. However, evalf/Int returns the correct numerical value of Pi.

 

Hi,

While computing a simple sequence of numbers, I remarked a small difference between the result obtained with $ and with seq.

Digits:=20:
u:=proc(n) evalf(((n+1)/n)^(n+1)) end proc:
a:=[u(n)$n=1..10]:
b:=[seq(u(n),n=1..10)]:
a-b;

 

The result is:

 

[0., 0., -4.*10^(-19), 0., 0., 6.*10^(-19), -9.*10^(-19), 0., -3.*10^(-19), 0.]

I have no idea why there are nonzero values in the output. Does anyone have an explanation?

 

It seems I get the correct values if I quote the expression before $:

a:=['u(n)'$n=1..10]:

However, it's not clear to me why this makes a difference in evalf.

Page 1 of 1