janhardo

690 Reputation

12 Badges

11 years, 36 days

MaplePrimes Activity


These are replies submitted by janhardo

@Aung 

This is another methode from acer of solving your expression than dharr did for your expression.

acer methode :
"Do you need a fully programmatic way to transform the integral of a sum into the sum of integrals? For example, programmatically extracting and re-using not just the integrand but also the ranges of integration and summation".

Suppose you take the first term of the sum and solve this integral by parts : what to do with this expression?

@dharr 

I'm not a fan of your code, which only shows maple commands.
Keep in mind , that someone is asking for your help and needs some more explanation. 

Make "free" a variable 

x := 5;  # Assigning a value to x
x := 'x';# Releasing the variable by resetting it to a symbol


                             x := 5

                             x := x

 

@janhardo 

# Definieer lijst van polynomen
L := [u[0]*ux[0]*uxx[0],
      u[0]*ux[0]*uxx[1] + u[0]*ux[1]*uxx[0] + u[1]*ux[0]*uxx[0],
      u[0]*ux[0]*uxx[2] + u[0]*ux[1]*uxx[1] + u[0]*ux[2]*uxx[0] +
      u[1]*ux[0]*uxx[1] + u[1]*ux[1]*uxx[0] + u[2]*ux[0]*uxx[0]]:

# Maak een lege tabel met kolommen voor de naam van het polynoom en zijn waarde
the_table := Array(1..0):
the_table ,= ["Polynoom", "Waarde"]:

# Toewijs elk polynoom aan een naam en voeg toe aan de tabel
for i from 1 to nops(L) do
    naam := cat("polynoom_", i-1);
    waarde := eval(L[i]);
    the_table ,= [naam, waarde]:
end do:

# Converteer de tabel naar lijstformaat voor presentatie
the_table := convert(the_table, listlist):
DocumentTools:-Tabulate(the_table, width=60):

 

# Definieer lijst van polynomen
L := [u[0]*ux[0]*uxx[0],
      u[0]*ux[0]*uxx[1] + u[0]*ux[1]*uxx[0] + u[1]*ux[0]*uxx[0],
      u[0]*ux[0]*uxx[2] + u[0]*ux[1]*uxx[1] + u[0]*ux[2]*uxx[0] +
      u[1]*ux[0]*uxx[1] + u[1]*ux[1]*uxx[0] + u[2]*ux[0]*uxx[0]]:

# Print de tabelkop met een vaste breedte
printf("%-12s %-60s\n", "Polynoom", "Waarde"):

# Print elke rij met polynoomnaam en corresponderende waarde
for i from 1 to nops(L) do
    naam := cat("polynoom_", i-1);
    waarde := eval(L[i]);
    printf("%-12s %-60s\n", naam, convert(waarde, string)):
end do:

Polynoom     Waarde                                                      
polynoom_0   u[0]*ux[0]*uxx[0]                                           
polynoom_1   u[0]*ux[0]*uxx[1]+u[0]*ux[1]*uxx[0]+u[1]*ux[0]*uxx[0]       
polynoom_2   u[0]*ux[0]*uxx[2]+u[0]*ux[1]*uxx[1]+u[0]*ux[2]*uxx[0]+u[1]*ux[0]*uxx[1]+u[1]*ux[1]*uxx[0]+u[2]*ux[0]*uxx[0]

 
 

 

Download polynoom_adomian_uitvoerprocedure_2_variabelen_in_tabel_7-11-2024.mw

seems that output:
[u[0]*ux[0]*uxx[0], u[0]*ux[0]*uxx[1] + u[0]*ux[1]*uxx[0] + u[1]*ux[0]*uxx[0], u[0]*ux[0]*uxx[2] + u[0]*ux[1]*uxx[1] + u[0]*ux[2]*uxx[0] + u[1]*ux[0]*uxx[1] + u[1]*ux[1]*uxx[0] + u[2]*ux[0]*uxx[0]]
could be correct in a different notation only 
to check...

L := [u[0]*ux[0]*uxx[0], 
      u[0]*ux[0]*uxx[1] + u[0]*ux[1]*uxx[0] + u[1]*ux[0]*uxx[0], 
      u[0]*ux[0]*uxx[2] + u[0]*ux[1]*uxx[1] + u[0]*ux[2]*uxx[0] + 
      u[1]*ux[0]*uxx[1] + u[1]*ux[1]*uxx[0] + u[2]*ux[0]*uxx[0]]:

# Toewijzen van elk element aan een dynamische naam L1, L2, ...
for i from 1 to nops(L) do
    assign(cat(L, i), L[i]);
end do:

# Weergeven van de variabelen en hun waarden
for i from 1 to nops(L) do
    print( polynome(i-1)= eval(cat(L, i)));
end do:

                polynome(0) = u[0] ux[0] uxx[0]

      polynome(1) = u[0] ux[0] uxx[1] + u[0] ux[1] uxx[0]

         + u[1] ux[0] uxx[0]

 polynome(2) = u[0] ux[0] uxx[2] + u[0] ux[1] uxx[1]

    + u[0] ux[2] uxx[0] + u[1] ux[0] uxx[1] + u[1] ux[1] uxx[0]

    + u[2] ux[0] uxx[0]

@salim-barzani 
If a algorithm is complet as info then i can try this 
Book notation is probably not  the same to get as in Maple example : 
Maybe to get this kind of notattion with the physics package in Maple ?

There is a polynome package in  Maple.
I do have here a book from André Heck ( a dutchman like me)  : introduction to Maple ..old, but maybe useful.

Mathematical computing: a introduktion  to programming in Maple ( +CD) 
This a really good book for basic learning programming in Maple ( but old) 
Partial Differential equation for comutional science ( with Maple and vectoranalyse (+CD)(non-lineair PDEs? , in general types of pdes in this book : heat, fluid mechanics, etc that's all  )
both books from author David Betounes

# Definieer de functie F(u, ux, uxx, uxxx) = u * ux * uxx
F := (u, ux, uxx, uxxx) -> u * ux * uxx;

@salim-barzani 
I am looking at your info , but it is not working yet

AdomianPolynomials := proc(F, n)
    local A, i, lam, term, expr, u_lam, ux_lam, uxx_lam, uxxx_lam, u, ux, uxx, uxxx, F_lam;

    # Definieer u, ux, uxx en uxxx als arrays met indexen van 0 tot n
    u := Array(0 .. n, [seq(u[i], i = 0 .. n)]);
    ux := Array(0 .. n, [seq(ux[i], i = 0 .. n)]);
    uxx := Array(0 .. n, [seq(uxx[i], i = 0 .. n)]);
    uxxx := Array(0 .. n, [seq(uxxx[i], i = 0 .. n)]);

    # Definieer de serie-expansies voor u(lam), ux(lam), uxx(lam), en uxxx(lam)
    u_lam := 0;
    ux_lam := 0;
    uxx_lam := 0;
    uxxx_lam := 0;

    for i from 0 to n do
        u_lam := u_lam + lam^i * u[i];
        ux_lam := ux_lam + lam^i * ux[i];
        uxx_lam := uxx_lam + lam^i * uxx[i];
        uxxx_lam := uxxx_lam + lam^i * uxxx[i];
    end do;

    # Bereken F(u, ux, uxx, uxxx) als functie van lam
    F_lam := F(u_lam, ux_lam, uxx_lam, uxxx_lam);

    # Initialiseer lijst A voor de Adomian polynomen
    A := [];

    # Bereken A0 door lam = 0 in te vullen
    term := subs(lam = 0, F_lam);
    A := [term];

    # Bereken hogere orde Ai termen
    for i from 1 to n do
        # Neem de i-de afgeleide naar lam
        expr := diff(F_lam, lam$i);
        term := subs(lam = 0, expr);
        A := [op(A), term / factorial(i)];
    end do;

    return A;
end proc:

# Definieer de functie F(u, ux, uxx, uxxx) = u * ux * uxx
F := (u, ux, uxx, uxxx) -> u * ux * uxx;

# Roep de procedure aan voor n = 2
AdomianPolynomials(F, 2);

AdomianPolynomials := proc(F, n)
    local A, i, lam, term, expr, u_lam, u;

    # Definieer u als een array met indexen van 0 tot n
    u := Array(0 .. n, [seq(u[i], i = 0 .. n)]);

    # Definieer de serie-expansie voor u(lam) als som van u[i] * lam^i termen
    u_lam := 0;
    for i from 0 to n do
        u_lam := u_lam + lam^i * u[i];
    end do;

    # Initialiseer lijst A voor de Adomian polynomen
    A := [];

    # Bereken A0 door lam = 0 in te vullen
    term := F(u[0]);
    A := [term];

    # Bereken hogere orde Ai termen
    for i from 1 to n do
        # Neem de i-de afgeleide naar lam
        expr := diff(F(u_lam), lam$i);
        term := subs(lam = 0, expr);
        A := [op(A), term / factorial(i)];
    end do;

    return A;
end proc:

# Definieer de functie F(u) = u^2
F := u -> u^2;

# Roep de procedure aan en geef de gewenste waarde van n door
AdomianPolynomials(F, 2);

proc (u) options operator, arrow; u^2 end proc

 

[u[0]^2, 2*u[0]*u[1], 2*u[0]*u[2]+u[1]^2]

(1)

[u0^2, 2*u0*u1, 2*u0*u2 + u1^2];# comparing

[u0^2, 2*u0*u1, 2*u0*u2+u1^2]

(2)

AdomianPolynomials := proc(F, n)
    local A, i, j, lam, term, expr, u_lam, v_lam, u, v;

    # Definieer u en v als arrays met indexen van 0 tot n
    u := Array(0 .. n, [seq(u[i], i = 0 .. n)]);
    v := Array(0 .. n, [seq(v[i], i = 0 .. n)]);

    # Definieer de serie-expansies voor u(lam) en v(lam)
    u_lam := 0;
    v_lam := 0;
    for i from 0 to n do
        u_lam := u_lam + lam^i * u[i];
        v_lam := v_lam + lam^i * v[i];
    end do;

    # Initialiseer lijst A voor de Adomian polynomen
    A := [];

    # Bereken A0 door lam = 0 in te vullen
    term := F(u[0], v[0]);
    A := [term];

    # Bereken hogere orde Ai termen
    for i from 1 to n do
        # Neem de i-de afgeleide naar lam
        expr := diff(F(u_lam, v_lam), lam$i);
        term := subs(lam = 0, expr);
        A := [op(A), term / factorial(i)];
    end do;

    return A;
end proc:

# Definieer de functie F(u, v) = u^2 + v^2
F := (u, v) -> u^2 + v^2;

# Roep de procedure aan voor n = 2
AdomianPolynomials(F, 2);

proc (u, v) options operator, arrow; v^2+u^2 end proc

 

[u[0]^2+v[0]^2, 2*u[0]*u[1]+2*v[0]*v[1], 2*u[0]*u[2]+u[1]^2+2*v[0]*v[2]+v[1]^2]

(3)
 

 

Download adomian_proc_mprimes_via_pdfv7-11-2024.mw

2 procedures for two variables adomian polynome geives the same result 

restart;

# Define the nonlinear function N(u) = u^2
N := u -> u^2;

# AdomianPolynomen Procedure (zoals beschreven in jouw code)
AdomianPolynomen := proc(N, u_series, n)
   local A, lambda, k, u_expansion, derivTerm;

   # Step 1: Set up the full series expansion for u(x, y) in terms of lambda
   u_expansion := add(lambda^k * u_series[k+1], k = 0 .. n);

   # Step 2: Compute N(u) applied to the series expansion
   derivTerm := N(u_expansion);

   # Step 3: Compute the n-th derivative with respect to lambda and evaluate at lambda = 0
   if n = 0 then
       A := eval(derivTerm, lambda = 0);
   else
       A := (1/factorial(n)) * diff(derivTerm, lambda$n);
       A := eval(A, lambda = 0);
   end if;

   return A;
end proc:

# Define the terms in the series expansion u_series
u_series := [x + y, x^2 + y^2, x*y, 0, 0, 0];

# Define the number of polynomials we want to compute
maxOrder := 2;  # Up to A_2 for testing

# Calculate Adomian polynomials up to maxOrder
for i from 0 to maxOrder do
    AdomianPoly := AdomianPolynomen(N, u_series, i);
    print(cat("Adomian polynomial A_", i, " is:"), AdomianPoly);
od;

"maple.ini in users"

 

proc (u) options operator, arrow; u^2 end proc

 

[x+y, x^2+y^2, x*y, 0, 0, 0]

 

2

 

(x+y)^2

 

"Adomian polynomial A_0 is:", (x+y)^2

 

2*(x+y)*(x^2+y^2)

 

"Adomian polynomial A_1 is:", 2*(x+y)*(x^2+y^2)

 

(x^2+y^2)^2+2*(x+y)*x*y

 

"Adomian polynomial A_2 is:", (x^2+y^2)^2+2*(x+y)*x*y

(1)

restart;

# Define the nonlinear function F(u) = u^2
F := u -> u^2;

# AdomianPolynomial Procedure (zoals beschreven in jouw code)
AdomianPolynomial := proc(F, n, x, y)
    local lambdaSeries, A_n, k, lambda, u, diffExpr;

    # Step 1: Define the symbolic terms u[k](x, y) for the series expansion
    u := (k, x, y) -> cat(u, k)(x, y);

    # Step 2: Build the helper series with lambda and symbolic terms u[k](x, y)
    lambdaSeries := add(lambda^k * u(k, x, y), k = 0 .. n);

    # Step 3: Compute the non-linear expression F applied to the helper series
    diffExpr := F(lambdaSeries);

    # Step 4: Compute the n-th derivative of diffExpr with respect to lambda
    if n = 0 then
        A_n := diffExpr;  # A0 is simply F(u0(x, y))
    else
        A_n := (1/factorial(n)) * diff(diffExpr, lambda $ n);
    end if;

    # Step 5: Evaluate the result at lambda = 0
    if n > 0 then
        A_n := subs(lambda = 0, A_n);
    end if;

    # Step 6: Simplify the result and return it
    A_n := simplify(A_n);
    return A_n;
end proc:

# Define the symbolic terms for the series expansion u(k, x, y)
# Equivalent to [x + y, x^2 + y^2, x*y, 0, 0, 0] from procedure 1
u0 := (x, y) -> x + y;
u1 := (x, y) -> x^2 + y^2;
u2 := (x, y) -> x*y;

# Calculate Adomian polynomials up to A_2 for comparison
A0 := AdomianPolynomial(F, 0, x, y);
A1 := AdomianPolynomial(F, 1, x, y);
A2 := AdomianPolynomial(F, 2, x, y);

# Display results
print("Adomian polynomial A_0 is:", A0);
print("Adomian polynomial A_1 is:", A1);
print("Adomian polynomial A_2 is:", A2);

"maple.ini in users"

 

proc (u) options operator, arrow; u^2 end proc

 

proc (x, y) options operator, arrow; x+y end proc

 

proc (x, y) options operator, arrow; y^2+x^2 end proc

 

proc (x, y) options operator, arrow; y*x end proc

 

(x+y)^2

 

2*(x+y)*(x^2+y^2)

 

(x^2+y^2)^2+2*(x+y)*y*x

 

"Adomian polynomial A_0 is:", (x+y)^2

 

"Adomian polynomial A_1 is:", 2*(x+y)*(x^2+y^2)

 

"Adomian polynomial A_2 is:", (x^2+y^2)^2+2*(x+y)*y*x

(2)
 

 

Download adomian_proc_2vriabelen_2_proceduresdezelfde_uitkomst_7-11-2024.mw

more abstract procedure for adomian 2 variable polynome , not subscripted, general use

abstracte_adomian_polynoom_2_variable_mapleprocedure_engels_.mw

Adomian polynomes for two variables

adoniam_polynoom_voor_2_variabelen_6-11-2024.mw

@salim-barzani 
There are two procedures for calculating adomian procedures for one variable here in this thread
- you can use code after using : AP1 := proc(f, M) or AP2 := proc(f, M)
- or built in the code by yourself as exercise into the two procedures code

Note: why would you want to destroy it..seems to be not useful for you?

# Define the list L
L := [%][]: # Adjust this list as desired
# Display the entire list
#print("The list L is:", L);
# Display each element individually with the name A[i]
for i from 1 to nops(L) do
    A[i-1] := L[i];
    #print(A[i-1]);
end do;

You can use this at the end of the procedures after calculation  or built it in. 

adomian_polynomenvia_mathematica_-boek_ode_zwillingr_info_A.mw

@salim-barzani 
Getting a procedure for 2 variables adomian polynoms ?
Seems to be in Mathematica no problem ( must test this), but a translation to maple code is unsure

# Define the list L
L := [%][]: # Adjust this list as desired
# Display the entire list
#print("The list L is:", L);
# Display each element individually with the name A[i]
for i from 1 to nops(L) do
    A[i-1] := L[i];
    #print(A[i-1]);
end do;

You can use this at the end of the procedures after calculation  or built it in. 
First 19 20 21 22 23 24 25 Last Page 21 of 73