janhardo

900 Reputation

13 Badges

11 years, 304 days
B. Ed math

MaplePrimes Activity


These are replies submitted by janhardo

@dharr There are multiple ways in Maple to solve mathematical problems. Well, I think it's quite an achievement to develop these procedural paths by you , compared to the code I produced.

@dharr 

That's a substantial procedure called paths.
Indeed, 510 paths, and the algorithm created seems shorter and uses a different calculation method.
Just for fun, I created an animation that shows all the paths.
There is no control mechanism code to check whether the number of paths is correct, but that is possible.
I take no credit whatsoever for this code,

restart:
with(plots):

interface(warnlevel=0):

# =====================================
# ROOSTER
# =====================================

W := 11:
H := 3:

start := [2,2]:
finish := [10,2]:

visited := Array(1..W,1..H,fill=false):

count := 0:

# =====================================
# ROOSTER TEKENEN
# =====================================

gridlines := []:

for i from 1 to W+1 do
    gridlines := [op(gridlines),
        plot([[i,1],[i,H+1]],color=gray)]:
od:

for j from 1 to H+1 do
    gridlines := [op(gridlines),
        plot([[1,j],[W+1,j]],color=gray)]:
od:

grid := display(gridlines):

# =====================================
# BEGIN- EN EINDPUNT MARKERING
# =====================================

startplot := pointplot(
    [[start[1]+0.5,start[2]+0.5]],
    symbol=solidcircle,
    symbolsize=20,
    color=green):

finishplot := pointplot(
    [[finish[1]+0.5,finish[2]+0.5]],
    symbol=solidcircle,
    symbolsize=20,
    color=red):

# =====================================
# BUURFUNCTIE
# =====================================

neighbors := proc(x,y)
local L,d,nx,ny;

L := [];

for d in [[1,0],[-1,0],[0,1],[0,-1]] do
    nx := x+d[1]:
    ny := y+d[2]:

    if nx>=1 and nx<=W and ny>=1 and ny<=H then
        L := [op(L),[nx,ny]]:
    fi:
od:

return L:

end proc:

# =====================================
# FRAMES OPSLAG
# =====================================

frames := []:

add_frame := proc(path)

global frames,count,grid,startplot,finishplot;

local pts,p1,p2,label,i,frame;

pts := [seq([path[i][1]+0.5,path[i][2]+0.5], i=1..nops(path))];

p1 := pointplot(
    pts,
    symbol=solidcircle,
    symbolsize=12,
    color=blue):

p2 := plot(
    pts,
    thickness=4,
    color=red):

label := textplot(
    [6,4,cat("Aantal gevonden paden = ",count)]
):

frame := display(
    [grid,p1,p2,startplot,finishplot,label],
    axes=none,
    scaling=constrained,
    view=[1..W+1,1..H+1]
):

frames := [op(frames), frame]:

end proc:

# =====================================
# DFS
# =====================================

DFS := proc(x,y,path,steps)

global visited,count,W,H,finish;

local nb,nx,ny;

if [x,y]=finish and steps=W*H then

    count := count+1:

    add_frame(path):

    return:

fi:

for nb in neighbors(x,y) do

    nx := nb[1]:
    ny := nb[2]:

    if not visited[nx,ny] then

        visited[nx,ny] := true:

        DFS(nx,ny,[op(path),[nx,ny]],steps+1):

        visited[nx,ny] := false:

    fi:

od:

end proc:

# =====================================
# START
# =====================================

visited[start[1],start[2]] := true:

DFS(start[1],start[2],[start],1):

# =====================================
# ANIMATIE
# =====================================

display(frames,insequence=true);

@KIRAN SAJJAN 
Can't make it more from it now
fig_8a_vraagmprimes_25-2-2026.mw

@Kitonum , Thank you, it's now clear what it's about.

@Kitonum 
How do you call this graph ?
Its not a Hamilton graph.

There is a Physics and DifferentialGeometry package and it seems that you can do this in both  packages 

Apparently, it works via a different type of derivative.
The differential geometry in Maple has a geometric object calculation from which components can be derived
In addition, the usual standard calculation method in Maple
I am trying to familiarize myself with the package.

 

 

 

restart:

with(DifferentialGeometry):
with(Tensor):
with(Tools):

#========================================================
# (1) Definieer de 2-sfeer S^2
#========================================================

DGsetup([theta, phi], S2):

g := evalDG( dtheta &t dtheta
           + sin(theta)^2 * dphi &t dphi ):

print("---- (1) METRIEK g ----"):

DGinfo(g, "ObjectType");
DGinfo(g, "ObjectComponents");
convert(g, DGArray);

#========================================================
# (2) Inverse metriek
#========================================================

ginv := InverseMetric(g):

print("---- (2) INVERSE METRIEK ----"):

DGinfo(ginv, "ObjectType");
DGinfo(ginv, "ObjectComponents");
convert(ginv, DGArray);

#========================================================
# (3) Directional derivative van scalar
#========================================================

X := D_theta + 2*D_phi:
f := cos(theta):

 Xf := DirectionalDerivative(X, f):

print("---- (3) DIRECTIONAL DERIVATIVE ----"):

#whattype(Xf);     # toont dat dit gewoon een scalar is
# DGinfo(Xf, "ObjectComponents");  # <-- zou fout geven!

#########  om een waarde te krijgen  JD ####
# Optioneel: met LieDerivative
Xf_lie := LieDerivative(X, f);
simplify(Xf_lie);

#========================================================
# (4) Christoffel-symbolen
#========================================================

Gamma := Christoffel(g):

print("---- (4) CHRISTOFFEL ----"):

DGinfo(Gamma, "ObjectType");
DGinfo(Gamma, "ObjectComponents");

# convert(Gamma, DGArray);  # <-- geeft fout (geen tensor!)

#========================================================
# (5) Riemann tensor
#========================================================

R := CurvatureTensor(g):

print("---- (5) RIEMANN TENSOR ----"):

DGinfo(R, "ObjectType");
DGinfo(R, "ObjectComponents");

#========================================================
# (6) Ricci tensor
#========================================================

Ric := RicciTensor(R):

print("---- (6) RICCI TENSOR ----"):

DGinfo(Ric, "ObjectType");
DGinfo(Ric, "ObjectComponents");
convert(Ric, DGArray);


#========================================================
# (7) Ricci scalar
#========================================================

Rscalar := RicciScalar(g):

print("---- (7) RICCI SCALAR ----"):

whattype(Rscalar);   # scalar, geen tensor

#========================================================
# (8) Gausskromming
#========================================================

detg := MetricDensity(g, 2):

K := simplify(
      DGinfo(R, "CoefficientList", [[1,2,1,2]])[1]
      / detg ):

print("---- (8) GAUSSKROMMING ----"):

K;

"---- (1) METRIEK g ----"

 

"tensor"

 

[[[1, 1], 1], [[2, 2], sin(theta)^2]]

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = sin(theta)^2})

 

"---- (2) INVERSE METRIEK ----"

 

"tensor"

 

[[[1, 1], 1], [[2, 2], 1/sin(theta)^2]]

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1/sin(theta)^2})

 

"---- (3) DIRECTIONAL DERIVATIVE ----"

 

Xf_lie := -sin(theta)

 

-sin(theta)

 

"---- (4) CHRISTOFFEL ----"

 

"connection"

 

[[[1, 2, 2], -(1/2)*sin(2*theta)], [[2, 1, 2], cot(theta)], [[2, 2, 1], cot(theta)]]

 

"---- (5) RIEMANN TENSOR ----"

 

"tensor"

 

[[[1, 2, 1, 2], sin(theta)^2], [[1, 2, 2, 1], -sin(theta)^2], [[2, 1, 1, 2], -1], [[2, 1, 2, 1], 1]]

 

"---- (6) RICCI TENSOR ----"

 

"tensor"

 

[[[1, 1], 1], [[2, 2], sin(theta)^2]]

 

Array(%id = 36893490623282316820)

 

"---- (7) RICCI SCALAR ----"

 

integer

 

"---- (8) GAUSSKROMMING ----"

 

sin(theta)^2/_DG([["tensor", S2, [[], [["bas", 2]]]], [[[], sin(theta)^2]]])

(1.1)
 

 

Download directionl_derative_word_lie_derative_nog_niet_berekend_16-2-2026.mw

@acer 

Use table then...but a procedure for this seems to be better, but for that  it is not a one- liner code length anymore.

toPrefix:=T->['table', seq([op(1,k),T[op(1,k)]], k in indices(T))]:

Warning, (in toPrefix) `k` is implicitly declared local
T:=table([f=a,q=s]):
toPrefix(T);

using  H := e ->eval(subsindets(e, algebraic, u -> `if`(type(u,atomic),
                       u, `[]`(op(0,u),op(u)))));

@Carl Love 
I had already made a calculation with the osculation circles, but I didn't know enough about it ,and the question was asked as a circle?
Interesting code example with the ~ operator

@sand15 

Suppose you draw a circle with center (0,0), then the points of intersection will touch the graph.
But not in this example, it are two tangent points
There is only one hyperbole type possible for two tangent points on the circle. 
hyperboolvergelijking_voor_2_ryaakpuontuen_aan_ciprkel_mprimes_10-.mw



 

restart:

# Conic and circle as functions
F := (x,y) -> A*x^2 + B*x*y + C*y^2 + D*x + E*y + F0;
G := (x,y) -> x^2 + y^2 - r^2:

# Expressions for differentiation
Fx := F(x,y):
Gx := G(x,y):

# Tangency condition (parallel gradients)
Detm := expand(
    diff(Fx,x)*diff(Gx,y)
  - diff(Fx,y)*diff(Gx,x)
):

# Conditions at ±(r,0)
eqs := [
    F(r,0) = 0,
    F(-r,0) = 0,
    subs({x=r,y=0},Detm) = 0,
    subs({x=-r,y=0},Detm) = 0
]:

# Eliminate A, C, F0
eliminate(eqs,{A,C,F0});

# Structural constraints
solve([
    r*(B*r - E) = 0,
    r*(B*r + E) = 0,
    2*D*r = 0
],[B,D,E]);

# Reduced conic
F2 := (x,y) -> A*x^2 + C*y^2 + F0;

# Normalize to standard form
Fstd := simplify(subs({A=-F0/a^2,C=F0/b^2}, F2(x,y))):
expr := simplify(Fstd/(-F0)):
simplify(expand(expr+1 = 1));

 

@sand15 
You could say there is space to draw a circle, but not tangent to the curve points is possible by circle geometry.
That f(0) is undefined, has nothing to do with the circle 

@Alfred_F 

If a left limit and a right limit for a function value are not the same , then there is no derivative function (geometrically a tangent line).

The function is continuous, but I do not know how Maple handles this. Maple will probably respond that the limit does not exist.  ( f(x)= |x| example ? )

@acer 
Thanks, so Maple calls a name with or without a value assigned to it a “variable” in a procedure application.

@acer 

But just looking at it from a practical point of view, how you work with variables in a procedure to calculate something.
Then the description I gave of a variable is correct, isn't it?
Note: 
Of course, I know the expression: "this depends on a lot of variables", without the variables in question changing in value.

@dharr 

How about this ?

1 2 3 4 5 6 7 Last Page 3 of 85