I need to set a "boundary" condition not at the boundaries of the computing domain but inside the domain during solving an ODE with FDM. The problem is a boundary value problem, which has been implemented based on pdetoae devised by @xzczd.
Prepare the mesh:
L = 6; domain = {-L, L}; points = 21; difforder = 4; grid = Array[# &, points, domain]; (*please find the function from the link above*) ptoafunc = pdetoae[u[x], grid, difforder];Discretize the system. Please note that the last condition
u'[0] == 0ofbcis what I want to impose inside the domain[-L,L]:eq = u[x] u'[x] + u''[x] + u''''[x] - 2*u'[x] == 0; bc = {u[-L] == 0, u[L] == 0, u'[-L] == 0, u'[L] == 0, u'[0] == 0}; del = #[[3 ;; -3]] &; ae = ptoafunc@eq // del; aebc = ptoafunc@bc;Solve the resulting system with
FindRoot:ic[x_] = 10*Cos[\[Pi]/(2 L) x]; solrule = FindRoot[{ae, aebc}, Table[{u@x, ic@x}, {x, grid}]]
Mathematica gives the following error:
FindRoot::nveq: "The number of equations does not match the number of variables in FindRoot[...]."
I also tried to remove one or two boundary conditions among the first four of bc, for example, u[-L] == 0,(*u[L] == 0,*)u'[-L] == 0,(*u'[L] == 0,*). However, the above error remains. Here, without the last condition u'[0] == 0, the code works well, but I need to additionally set this "boundary" condition to obtain a special function $u(x)$.
Thank you for any suggestion!
Update (according to xzczd's suggestion): Such a b.c could be imposed with
midcond = ptoafunc[u'[0] == 0][[(points + 1)/2]]
Now we would have 5 b.c.s, and the problem appears to be ill-posed, so the code gives the same warning again. Thus, we must remove one of them. Next, using aebc = ptoafunc@bc~Join~{midcond} as the new b.c.s. FindRoot gives a reasonable solution.
pdetoaecannot handle b.c. that's inside the domain, it'll just discretizeu'[0]==0as if it'su'[x]==0, just executeptoafunc[u'[0]==0]and observe. It's not hard to circumvent this, you can usePartto extract the needed b.c. fromptoafunc[u'[0]==0]. However, are you sure these 5 b.c.s form a well-posed problem? Notice imposing b.c. inside the domain is essentially equivalent to split the original domain. – xzczd Jun 18 '19 at 06:54u[x]=0. – Alex Trounev Jun 18 '19 at 11:38u=0. However, I want to find the non-trivial ones :) – lxy Jun 18 '19 at 12:28