|
From: Dr. W. L. <dr....@gm...> - 2023-07-21 06:07:57
|
Hi Richard,
thank you very much for your kind advice. I would like to comment on it a little bit.
1. Please note that the code is aimed at beginners who use Maxima _online_ (which doesn't know e.g. concat, hence my request and the work around with hard coding the names of the unknowns yi) e.g. on their iPhones.
RJF> "FDM appears to do nothing but set up global values .."
2. to the FDM function:
please note, that in addition to set up the required variables, it also provides the main work:
- discretization of the ODE
- setting up the system of equations in (2)
- solving the system in (3).
FDM therefore aims to do what the name says ;)
3. on the BVP function:
it should translate the given ODE into its discretization as 1:1 as possible - as stated in the comment before.
It should therefore be formulated by the novice (of Maxima and method) IMO immediately before calling the FDM method.
it was also my intention to formulate FDM/BVP for the beginner as briefly (13 lines) as possible - a general (more professional) library variant was therefore not intended. It is teaching code that follows a previously presented example as a summary. Therefore I should name the title „generalized“ and not „general procedure“ ;)
RJF> "It seems plausible to recode using subscripted names as a[1], a[2].."
Yes, I will try to use subscripted names if it allows to avoid hard coding of the system variables yi in „yamwi" (which was the impetus of my original question). Clearly, there was no such problem using original Maxima.
Anyway: Here is the code from the screenshot if anyone wants to try it in maxima_online_ („yamwi“):
/* MAXIMA-ONLINE : FINITE DIFFERENCE METHOD (FDM) for BVP --- */
FDM(xo,xe,a,b,n):= block(
h : (xe-xo)/n,
x(k) := xo + k*h,
y : [y0,y1,y2,y3,y4,y5,y6,y7,y8,y9], /* (1) */
yn : y[n+1],
yp(k) := (y[k+2]-y[k])/(2*h),
ypp(k):= (y[k]-2*y[k+1]+y[k+2])/h^2,
Eqs: flatten([y0=a, makelist( BVP(i),i,1,n-1), yn=b]), /* (2) */
Y : map(rhs, linsolve(Eqs, y)) )$ /* (3) */
/* Test BVP: y''+0.2y'+4y=3x+1 BC: y(0)=0.1=a, y(1)= 0.7=b */
fpprintprec:5$ ratprint:false$
BVP(k) := ypp(k) + 0.2*yp(k) + 4*y[k+1] = 3*x(k)-1; /* (4) */
FDM(xo:0, xe:1, a:0.1, b:0.7, n:4), numer; /* (5) */
Here is the link to Maxima-on-line:
http://maxima.cesga.es/index.php?c=nqxtw25ed62tu5x2eicib&n=0
Best regards,
Wolfgang
> Am 20.07.2023 um 19:33 schrieb Richard Fateman <fa...@gm...>:
>
> Hi Wolfgang:
>
> think this FDM program is somewhat counter to the way programs are
> usually written in a "functional" style . FDM
> appears to do nothing but
> set up global values for h, x(k), y, yn, yp(k) and ypp(k), Y [distinct from y] and Eqs.
>
> The text then shows how to use the program BVP, on this data, which
> appears to work only for the case n=8, which is hard-coded into FDM.
>
> It seems plausible to recode using subscripted names as a[1], a[2], ...., rather than
> a1,a2, ... as Robert suggests. (using concat would not be so terrible, either. e.g. a[i]:=concat(a,i) would do it)
>
> It would be traditional to encode a DE using 'diff(y,t), 'diff(y,t,2) .
> Presumably one would introduce the discretization yp, and ypp as part of the solution procedure.
>
> Maybe this works as given on exactly this example, but I think that
> if it were to be included in some library it deserves a little work to be
> generalized. Perhaps by you?
>
>
>
>
> On Thu, Jul 20, 2023 at 9:50 AM Dr. Wolfgang Lindner <dr....@gm... <mailto:dr....@gm...>> wrote:
> Dear David, dear Robert,
>
> Thank you all for your advice.
> The problem is attached, it shows up only in Maxima_online - I suspect an old version of Maxima running behind the scene.
>
> HTH Wolfgang
>
>
> <bvp.jpeg>
>
>> Am 20.07.2023 um 18:34 schrieb Robert Dodier <rob...@gm... <mailto:rob...@gm...>>:
>>
>> On Thu, Jul 20, 2023 at 4:21 AM Dr. Wolfgang Lindner
>> <dr....@gm... <mailto:dr....@gm...>> wrote:
>>
>>> Is it possible to construct y =[y0, y1, y2, y3, y4] i.e.
>>>
>>> y : makelist (concat (y,i), i,0, 4);
>>>
>>> without reference/using to concat ?
>>
>> Maybe you can say more about what you need to accomplish. Without
>> knowing more, my advice is to avoid constructed symbols, and work with
>> subscripted symbols (y[0], etc) instead.
>>
>> best,
>>
>> Robert
|