dharr

Dr. David Harrington

9157 Reputation

22 Badges

21 years, 281 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 replies submitted by dharr

@salim-barzani I have edited it to say that it was the [4,3,1] case. Here is how I understand what you asked for.

In your question you want to know how to solve all neural net cases. You gave

(1) a paper describing the method and solving Eq 1 for some specific neural networks [4,3,1] and [4,2,2,1] with specific functions.

(2) a worksheet t1.mw for Eq 1 the [4,3,1] case with the same activation functions as in the paper, which leads to an error.

(3) a worksheet t2-true-one.mw for Eq. 1 for the [4,2,2,1] case with the same functions as in the paper.

and the comment "t1 have problem about  first case of layer and t2 dont have problem".

I explained the error in t1.mw, which for some reason you did differently from t2-true-one. So you can now complete that case. In both these cases you used a different methodology before you started the neural net part, so you arrived at different solutions from in the paper.

In response you explained you have a generator for the neural network equation that can be supplied the the type of neural network and any desired functions.

I wanted to understand whether the paper method is somehow different from your method in the sense of what "term" means in "setting the coefficients of each term to zero". So I managed to replicate the paper solution for set 1 of the [4,3,1] case. So at this point you know how to solve Eq. 1 using neural networks, getting two types of solutions (your method in t2-true-one.mw and the paper method using Hirota transformations).

So now you are giving more papers and worksheets, which I am not going to read. I think you want to somehow find all cases. But the paper says "activation function which can be interpreted arbitrarily" (any function) and you already have a generator for the different types of neural network so as far as I can see you have everything you need.

If you are asking for some huge procedure that does everything, then the problem would need to be very carefully specified. Aside from the fact that there is a lot of work doing argument checking etc., I have been reluctant to make such procedures in the past for two reasons: (1) you jump between different types of equations, methodologies, numbers of parameters etc and so the problem description is insufficiently precise, and (2) I want to provide lines of code that are simple enough that you can understand them and modify them yourself (my background as an educator I guess).

You should not use =0 if you are going to use numer(normal(...)) or collect etc. That was the main error. I didn't attempt to follow the logic, but coeff doesn't work on a set.

t1.mw

@sand15 I was aware of the ambiguity in natural numbers. In New Zealand we learnt that it started with 1.
Note that with 3 sign changes, the number of positive solutions is 3 or 1 (multiples of two less than the number of sign changes is also possible).

But the cubic is probably the way to go; large integer solutions may come from finding integer/rational points on elliptic curves.

@sand15 I assume by natural numbers are meant {1,2,3,...}, i.e., not including zero.

@Alfred_F @vv So the case I chose is not a Holditch curve, in the notation of the Monterde and Rochera paper. But empirically it still seems to have area/ab = Pi. 

@acer Yes, missed that and I misread cos(x),sin(x*y)  as cos(x)*sin(x*y) and was focused on the issue with the parameter part of the dsolve procedure. It would be easier if the OP uploaded a worksheet.

[Edit: it is an evaluation problem, but my solution is for a regular, not parametric plot.[

The problem is the x in the plot(h(7.7,x),..) call. When you call plot, h(7.7,x) is evaluated, and the result is the error message because the parameter x does not have a value. The solution is to add the line

if not [k,x]::[numeric,numeric] then return 'procname'(_passed) end if;

at the beginning of h so that the call returns unevaluated if it does not get numeric values of k and x, and the procedure from dsolve is never invoked. Later internally within plot, it gets numeric values of x that are plotted.

The reason that f does not lead to the same problem is that its evaluation gives an expression in x that does not lead to an error.

@Alfred_F I was working on an animation. Still a bit buggy for some curves; the code pushes one end of the chord (with the magenta dot), and solves for the other end, but there are two solutions for the other end and it sometimes jumps from one to the other or can't solve.

There are discontinuities in this case but area/ab still seems to be Pi (3.135453491). The file was too large to load with output. (I should not include the original curve in each frame of the animation.)

Curve2.mw

@vv That's helpful. I was puzzling over what "the point in which the chord intersects its consecutive position" meant.

@C_R Not sure it is related, but here are a couple more puzzles with ditto.

restart

interface(version)

`Standard Worksheet Interface, Maple 2026.1, Windows 11, April 28 2026 Build ID 2011354`

a+b; %-op(2, %)

Error, invalid sum/difference

"a+b; %-op(2,`%`);"

Converted to 1D

 a+b; `%`-op(2,`%`);

a+b

a

a; b; %-`%%`

Error, invalid sum/difference

"a;b; %-`%%`;"

Converted to 1-D

a;b; `%`-`%%`; ;

a

b

b-a

 

 

Download ditto.mw

@salim-barzani The case here in the paper with e[1]=0 does not need the full analysis since it reduces to a quadratic in w^2, so it is simple to go through all the cases. I used here e[i] but in the worksheets with the pdes I used e__i.

restart

For a complex-conjugate pair of roots w1+`&+-`(I*w2) we can write this as the form on the rhs, which is used in the table

(w-w1-I*w2)*(w-w1+I*w2) = (w-w1)^2+w2^2; simplify((rhs-lhs)(%))

(w-w1-I*w2)*(w-w1+I*w2) = (w-w1)^2+w2^2

0

So the cases in the table are

(I) a complex-conjugate pair that occurs twice

(II) 1 single real root of multiplicity 4 (the root must be zero)

(III) a real root of multiplicity 2 and a different real root of multiplicity 2

(IV) a real root of multiplicity 3 and a real root of multiplicity 1

(V) a real root of multiplicity 2 and a complex-conjugate pair

(VI) four real roots all different

(VII) two different real roots and a complex conjugate pair

(VIII) two different complex conjugate pairs

(IX) a real root of multiplicity 2 and two other different real roots.

p := w^4+w^2*e[2]+w*e[1]+e[0]

w^4+w^2*e[2]+w*e[1]+e[0]

The discriminant is zero iff multiplicity > 1. This is four times theD__4 in the paper

d := discrim(p, w)

16*e[0]*e[2]^4-4*e[1]^2*e[2]^3-128*e[0]^2*e[2]^2+144*e[0]*e[1]^2*e[2]-27*e[1]^4+256*e[0]^3

But for e[1] = 0, our polynomial and the discriminant simplifies to

p1 := eval(p, e[1] = 0); factor(eval(d, e[1] = 0))

w^4+w^2*e[2]+e[0]

16*e[0]*(-e[2]^2+4*e[0])^2

So if e[0]<>0 and e[0] <> e[2]^2/4 then all roots are distinct. This is cases (VI), (VII) and (VIII). As in the table D4<>0 in these cases and D4 = 0 for all the other cases.
If we have 4*e[0] = e[2]^2 then we have multiple roots. But in this case the polynomial is a perfect square and we have cases (I), (II), or (III). If e[2] is positive then the roots are imaginary and we have case (I) with w1=0. So anywhere in the paper for case (I) that w1 appears it should be set equal to zero. If e[2] is positive then we have case (III). If e[2] = 0 (and therefore e[0] = 0) then we have case (II).

eval(p1, e[0] = (1/4)*e[2]^2); factor(%); solve(%, w)

w^4+w^2*e[2]+(1/4)*e[2]^2

(1/4)*(2*w^2+e[2])^2

(1/2)*(-2*e[2])^(1/2), -(1/2)*(-2*e[2])^(1/2), (1/2)*(-2*e[2])^(1/2), -(1/2)*(-2*e[2])^(1/2)

The other way for the discriminant to be zero is e[0] = 0. So the other cases (IV), (V), and (IX) with multiple roots but not perfect squares must arise from e[0] = 0 and e[0] <> e[2]^2/4.

Now if e[0]=0 then two of the roots are zero anyway and the other two are +/- sqrt(-e[2])

factor(eval(p1, e[0] = 0)); solve(%, w)

w^2*(w^2+e[2])

0, 0, (-e[2])^(1/2), -(-e[2])^(1/2)

So if e[2] = 0 we have the case (II) we saw already. If e[2] > 0 we have two roots zero and two imaginary which is case (V) with w1 = w2 = 0.

If e[2] < 0 then we have case (IX) with w1 =0, w2 = -w3 = sqrt(-e[2]).

We have exhausted all cases; case (IV) cannot arise iin this paper where e[1]=0.

 

Note that D3 given in the paper simplifies for e[1] = 0 to

D2 := factor(eval(-2*e[2]^3+8*e[0]*e[2]-9*e[1]^2, e[1] = 0))

2*e[2]*(-e[2]^2+4*e[0])

so if e[0] = e[2]^2/4 then both D3 and D4 are zero.
Note also that D2 = -e[2] so we can check that with the above.

NULL

Download DiscrimChain.mw

I see now you flipped the sign of c in your substitution, to make every thing consistently x+y-c*t.So the authors consistently used x+y+c*t. To get the plot orientation right you need x+y+c*t or use your convention and a negative c value in producing the plot.

Here it is altogether - you can change the line with xtc to change the convention.

derivation.mw

@salim-barzani Excellent. You used xi = x+y-c*t. I figured out that for the plots you need xi = x+y+c*t to get the correct orientation, but then pde2 is not satisfied. So the authors must have used xi = x+y-c*t in deriving the substitution in 3.4 but xi = x+y+c*t elsewhere. It is in any case just a matter of changing the sign of c.

@salim-barzani You have u and v in pde1 and pde2 in a way that I didn't understand. The paper says xi = x+y+c*t but you have x+y-c*t (which seems better to me). Either way pde1 is satisfied but pde2 is not. Perhaps something is not right about the derivation in Eqs 3.1-3.5?

P5-pde.mw

Here's further back to psi and fig 1. I had v=u^3/3 instead of v=u^2/3 earlier; now everything looks correct.

Subcases (1) and (3)

restart

with(PDEtools)

undeclare(prime, quiet)

declare(u(xi), quiet); declare(w(`&xi;__1`), quiet)

Eq 3.5

ode := (diff(u(xi), xi))^2 = delta*u(xi)^4+(beta*p^3+p*q-r)*u(xi)^2/(3*beta*p+1)+g[0]

(diff(u(xi), xi))^2 = delta*u(xi)^4+(beta*p^3+p*q-r)*u(xi)^2/(3*beta*p+1)+g[0]

Eq 3.6 with epsilon = 1

itr := {`&xi;__1` = delta^(1/4)*xi, w(`&xi;__1`) = delta^(1/4)*u(xi)}

{xi__1 = delta^(1/4)*xi, w(xi__1) = delta^(1/4)*u(xi)}

tr := solve(itr, {xi, u(xi)})

{xi = xi__1/delta^(1/4), u(xi) = w(xi__1)/delta^(1/4)}

Eq. 3.7

ode2 := dchange(tr, ode, [`&xi;__1`, w(`&xi;__1`)], params = {delta})

(diff(w(xi__1), xi__1))^2 = w(xi__1)^4+(beta*p^3+p*q-r)*w(xi__1)^2/(delta^(1/2)*(3*beta*p+1))+g[0]

Eq 3.7 in terms of e2 and e0

ode3 := subs(1/sqrt(delta) = e__2*(3*beta*p+1)/(beta*p^3+p*q-r), g[0] = e__0, ode2)

(diff(w(xi__1), xi__1))^2 = w(xi__1)^4+e__2*w(xi__1)^2+e__0

F := subs(w(`&xi;__1`) = W, rhs(ode3))

W^4+W^2*e__2+e__0

F2 := collect(((W-w__1)^2+w__2^2)^2, W)

W^4-4*w__1*W^3+(6*w__1^2+2*w__2^2)*W^2-4*(w__1^2+w__2^2)*w__1*W+(w__1^2+w__2^2)^2

 

For the coefficients of w^3 to be the same we need w1 = 0. Then for the coeffs of w^2 and 1 we need to solve

F21 := eval(F2, w__1 = 0); eqs := {coeff(F21, W^2) = coeff(F, W^2), coeff(F21, W, 0) = coeff(F, W, 0)}

W^4+2*W^2*w__2^2+w__2^4

{w__2^4 = e__0, 2*w__2^2 = e__2}

There is no solution for w2 unless we have some special relationship between e[2] and e[0]

eliminate(eqs, w__2); eq := %[1][2][]; eq0 := e__0 = solve(eq, e__0)

[{w__2 = -(1/2)*2^(1/2)*e__2^(1/2)}, {-e__2^2+4*e__0}], [{w__2 = (1/2)*2^(1/2)*e__2^(1/2)}, {-e__2^2+4*e__0}]

-e__2^2+4*e__0

e__0 = (1/4)*e__2^2

So with this substitution we can work out the integral. The result has a slightly different form since w1 =0

factor(eval(F, eq0)); `assuming`([Int(1/sqrt(%), W)], [2*W^2+e__2 > 0]); eqxi1 := `&xi;__1` = value(%)+`&xi;__10`

(1/4)*(2*W^2+e__2)^2

Int(1/(W^2+(1/2)*e__2), W)

xi__1 = 2^(1/2)*arctan(W*2^(1/2)/e__2^(1/2))/e__2^(1/2)+xi__10

So the solution to ode3 for this is

sol3 := w(`&xi;__1`) = solve(eqxi1, W)

w(xi__1) = (1/2)*tan((1/2)*e__2^(1/2)*(xi__1-xi__10)*2^(1/2))*e__2^(1/2)*2^(1/2)

odetest(sol3, eval(ode3, eq0))

0

Convert back to earlier constants. We have e0 = g[0] =e2^2/4 so change

eqe2 := e__2 = (beta*p^3+p*q-r)/(sqrt(delta)*(3*beta*p+1)); eqg0 := g[0] = rhs(eval(eq0, eqe2)); ode2b := eval(ode2, eqg0); sol2 := simplify(eval(sol3, eqe2))

e__2 = (beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1))

g[0] = (1/4)*(beta*p^3+p*q-r)^2/(delta*(3*beta*p+1)^2)

(diff(w(xi__1), xi__1))^2 = w(xi__1)^4+(beta*p^3+p*q-r)*w(xi__1)^2/(delta^(1/2)*(3*beta*p+1))+(1/4)*(beta*p^3+p*q-r)^2/(delta*(3*beta*p+1)^2)

w(xi__1) = (1/2)*tan((1/2)*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*(xi__1-xi__10)*2^(1/2))*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*2^(1/2)

odetest(sol2, ode2b)

0

So now transform back to u(xi)

itr2 := {`&xi;__10` = delta^(1/4)*`&xi;__0`}

solu := dchange(`union`(itr, itr2), sol2/delta^(1/4), [u(xi), xi, `&xi;__0`], params = {delta}); odeb := eval(ode, eqg0)

u(xi) = (1/2)*tan((1/2)*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*(delta^(1/4)*xi-delta^(1/4)*xi__0)*2^(1/2))*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*2^(1/2)/delta^(1/4)

(diff(u(xi), xi))^2 = delta*u(xi)^4+(beta*p^3+p*q-r)*u(xi)^2/(3*beta*p+1)+(1/4)*(beta*p^3+p*q-r)^2/(delta*(3*beta*p+1)^2)

odetest(solu, odeb)

0

So v(xi) is, from Eq. 3.2

solv := v(xi) = eval(-(1/3)*u(xi)^2, solu)

v(xi) = -(1/6)*tan((1/2)*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*(delta^(1/4)*xi-delta^(1/4)*xi__0)*2^(1/2))^2*(beta*p^3+p*q-r)/(delta*(3*beta*p+1))

And so psi is perhaps? (There is something about taking the real part I didn't understand.)

psi := MakeFunction(eval(rhs(solv), xi = c*t+x+y), x, y, t)

proc (x, y, t) options operator, arrow; -(1/6)*tan((1/2)*((beta*p^3+p*q-r)/(delta^(1/2)*(3*beta*p+1)))^(1/2)*(delta^(1/4)*(c*t+x+y)-delta^(1/4)*xi__0)*2^(1/2))^2*(beta*p^3+p*q-r)/(delta*(3*beta*p+1)) end proc

Figure 1 (psi may be scaled differently). Not sure which is x and which is t

psi1 := eval(psi(x, 0, t), {`&xi;__0` = 0, beta = 1, c = 1/4, delta = 1/6, p = -1/2, q = 2*sqrt(6)*(1/3), r = -1/8})

-(2/3)*tan((1/12)*4^(1/2)*6^(3/4)*((1/4)*t+x)*2^(1/2))^2*6^(1/2)

plot3d(psi1, t = -10 .. 10, x = -10 .. 10, view = [default, default, -40 .. 2], orientation = [55, 55])

plot(eval(psi1, t = 0), x = -10 .. 10, -40 .. 2)

Subcase (3) is the same function, just written in a different way. Fig. 3:

psi4 := eval(psi(x, 0, t), {`&xi;__0` = 0, beta = 1, c = 1/4, delta = 1/6, p = -1/2, q = -(1/2)*sqrt(6), r = -1/8})

(1/2)*tan((1/12)*(-3)^(1/2)*6^(3/4)*((1/4)*t+x)*2^(1/2))^2*6^(1/2)

plot3d(psi4, t = -5 .. 5, x = -5 .. 5, view = [default, default, -2 .. 0], orientation = [55, 55])

NULL

Download fp3.mw

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