janhardo

810 Reputation

12 Badges

11 years, 204 days

MaplePrimes Activity


These are replies submitted by janhardo

DeepSeek ai seems to be smarter then ChatGPT...
Exploreplot 

By Perform travelling wave substitution using dchange,  the pde transform into a ode (reduction) 
This is working in default notation, but with a diff_table notation ?

default notation
restart;
with(PDEtools):

# Step 1: Define the PDE
declare(u(x,t));
pde := diff(u(x,t), t$2) + a^2*diff(u(x,t), x$2) = b*exp(beta*u(x,t));

# Step 2: Perform travelling wave substitution using dchange
# Transformation to the travelling wave coordinate z = x - c*t
tr := {x = z + c*tau, t = tau, u(x,t) = U(z)};
new_pde := dchange(tr, pde, [z, tau, U(z)]);

# Step 3: Simplify the resulting ODE (derivatives with respect to tau vanish)
ode := simplify(new_pde) assuming tau::constant;

# Step 4: Solve the ODE
sol := dsolve(ode, U(z));

# Display the solution
sol;

Can it ever be solved  exact ?
Finding real valued parameters for this function and and at the same time a solution for a npde 

Get rid of the sqrt ?..take the inverse  operation for this.

It's not yet clear to me exactly what you want to do.
- there is a plane. 
- there is a placevector( in Dutch :plaatsvector)  ( start in origin). 
The place vector intersects the plane and an intersection point should be calculated from it?

L4 has a crossterm  x*t  and coeffs command is not working for this ?

Now there is no plot , because k is a unknown




Lets take for k= 1 

Is a one -liner from which there is nothing to learn in my opinion , has no educational value 

@dharr 
# Almost all Maple commands, such as solve, dsolve etc interpret an expression without =0 as though the =0 was present.# ?
check this with ODEsteps 

Two commands for getting a fieldplot for differential equations 


 

Module ODEgenerator 18-1-2025

 

restart;

 

odegenerator := module()
    option package;
  export odegeniter, odegenman;# odegenexpl;
  
######################
  odegeniter := proc(V, t, y, differential_eq, solve_all, range)
    local a0, a1, a2, b0, b1, eq, rows, row_eqs, numrows, i, single_row, selected_rows, dataframe;
    uses PDEtools;

    # Check if the input is a valid differential equation
    if not has(differential_eq, diff(y(t), t)) then
        error "The 'differential_eq' parameter must be a valid differential equation containing diff(y(t), t).";
    end if;

    # Validate solve_all and range parameters
    if not (solve_all = true or solve_all = false) then
        error "The solve_all parameter must be true or false.";
    end if;

    if not (range = 0 or type(range, posint) or type(range, range)) then
        error "The range parameter must be 0, a positive integer, or a range (e.g., 1..5).";
    end if;

    # Initialize storage for equations and solutions
    rows := [];
    row_eqs := [];

    # Iterate through all combinations of parameters in V
    for a0 in V do
        for a1 in V do
            for a2 in V do
                for b0 in V do
                    for b1 in V do
                        # Substitute parameters into the differential equation
                        eq := differential_eq;
                        eq := subs('a__0' = ifelse(a0 = 0, infinity, a0), eq);
                        eq := subs('a__1' = ifelse(a1 = 0, infinity, a1), eq);
                        eq := subs('a__2' = ifelse(a2 = 0, infinity, a2), eq);
                        eq := subs('b__0' = ifelse(b0 = 0, infinity, b0), eq);
                        eq := subs('b__1' = ifelse(b1 = 0, infinity, b1), eq);

                        # Add the equation to the rows
                        rows := [op(rows), [nops(rows) + 1, a0, a1, a2, b0, b1, eq, ""]];
                        row_eqs := [op(row_eqs), eq];
                    end do;
                end do;
            end do;
        end do;
    end do;

    # Get the number of rows generated
    numrows := nops(rows);

    # Generate the full DataFrame when solve_all is true and range is 0
    if solve_all = true and range = 0 then
        printf("Generating full DataFrame...\n");
        for i to numrows do
            try
                rows[i][8] := rhs(dsolve(row_eqs[i], y(t)));
            catch:
                rows[i][8] := "No explicit solution";
            end try;
        end do;

        # Create and return the DataFrame
        dataframe := DataFrame(Matrix(rows), columns = ['Row', 'a__0', 'a__1', 'a__2', 'b__0', 'b__1', 'Equation', 'Solution']);
        return dataframe;

    elif solve_all = true and type(range, posint) then
        # Retrieve a specific row from the DataFrame
        printf("Retrieving row %d from DataFrame...\n", range);
        if range > numrows then
            error "Row index out of bounds.";
        end if;
        single_row := rows[range];
        try
            single_row[8] := rhs(dsolve(row_eqs[range], y(t)));
        catch:
            single_row[8] := "No explicit solution";
        end try;
        return DataFrame(Matrix([single_row]), columns = ['Row', 'a__0', 'a__1', 'a__2', 'b__0', 'b__1', 'Equation', 'Solution']);

    elif solve_all = true and type(range, range) then
        # Retrieve rows within a specified range
        printf("Retrieving rows %a from DataFrame...\n", range);
        selected_rows := [];
        for i from op(1, range) to op(2, range) do
            if i > numrows then
                error "Row index out of bounds.";
            end if;
            selected_rows := [op(selected_rows), rows[i]];
            try
                selected_rows[-1][8] := rhs(dsolve(row_eqs[i], y(t)));
            catch:
                selected_rows[-1][8] := "No explicit solution";
            end try;
        end do;

        # Return the selected rows as a DataFrame
        return DataFrame(Matrix(selected_rows), columns = ['Row', 'a__0', 'a__1', 'a__2', 'b__0', 'b__1', 'Equation', 'Solution']);

    else
        error "Invalid combination of solve_all and range.";
    end if;
 end proc:

 ################
  odegenman := proc(V, x, y, differential_eq, const_values, xrange, yrange, initial_conditions)
    local a0, a1, a2, b0, b1, sol, Fsol, row_number, count,
          a0_iter, a1_iter, a2_iter, b0_iter, b1_iter, modified_eq, eq_type, odeplot_cmd;
    uses PDEtools, plots;

    # Check if const_values is valid
    if not type(const_values, list) or nops(const_values) <> 5 then
        error "The constant values (const_values) must be a list with exactly 5 elements.";
    end if;

    # Check if xrange and yrange are valid
    if not type(xrange, range) or not type(yrange, range) then
        error "Both xrange and yrange must be ranges, e.g., 0..2 or -10..10.";
    end if;

    # Check if initial_conditions is a valid list
    if not type(initial_conditions, list) or nops(initial_conditions) = 0 then
        error "Initial conditions must be provided as a non-empty list.";
    end if;

    # Assign the constant values
    a0 := const_values[1];
    a1 := const_values[2];
    a2 := const_values[3];
    b0 := const_values[4];
    b1 := const_values[5];

    # Find the row number by unique identification
    count := 1;
    row_number := "Unknown";  # Default value if no row is found
    for a0_iter in V do
        for a1_iter in V do
            for a2_iter in V do
                for b0_iter in V do
                    for b1_iter in V do
                        if [a0_iter, a1_iter, a2_iter, b0_iter, b1_iter] = const_values then
                            row_number := sprintf("%d", count);  # Convert to string
                        end if;
                        count := count + 1;
                    end do;
                end do;
            end do;
        end do;
    end do;

    # Create a modified version of the differential equation
    modified_eq := differential_eq;

    if a0 = 0 then
        modified_eq := subs('a__0' = infinity, modified_eq);  # Disable term
    else
        modified_eq := subs('a__0' = a0, modified_eq);
    end if;

    if a1 = 0 then
        modified_eq := subs('a__1' = infinity, modified_eq);
    else
        modified_eq := subs('a__1' = a1, modified_eq);
    end if;

    if a2 = 0 then
        modified_eq := subs('a__2' = infinity, modified_eq);
    else
        modified_eq := subs('a__2' = a2, modified_eq);
    end if;

    if b0 = 0 then
        modified_eq := subs('b__0' = infinity, modified_eq);
    else
        modified_eq := subs('b__0' = b0, modified_eq);
    end if;

    if b1 = 0 then
        modified_eq := subs('b__1' = infinity, modified_eq);
    else
        modified_eq := subs('b__1' = b1, modified_eq);
    end if;

    # Evaluate the type of the ODE
    eq_type := DEtools:-odeadvisor(modified_eq);

    # Solve the equation symbolically
    printf("The corresponding row number is: %s\n", row_number);
    printf("The simplified ODE with the given coefficients is:\n\n");
    print(modified_eq, eq_type);

    printf("Attempting to solve symbolically...\n");
    try
        sol := dsolve(modified_eq, y(x));
        if type(sol, `=`) then
            Fsol := rhs(sol);
            printf("Explicit symbolic solution found:\n");
            print(Fsol);
        else
            Fsol := "No explicit solution (analytically).";
            printf("No explicit symbolic solution found for the differential equation. A DEplot will be generated numerically.\n");
        end if;
    catch:
        Fsol := "Symbolic solution failed.";
        printf("Symbolic solution failed. A DEplot will be generated numerically.\n");
    end try;

    # Generate the DE plot numerically
    printf("Generating DE plot for the differential equation...\n");
    try
        odeplot_cmd := DEtools:-DEplot(
            modified_eq,
            [y(x)],
            x = xrange,
            initial_conditions,
            y = yrange,
            stepsize = 0.1,
            title = "DE Plot for Differential Equation"
        );
        print(plots:-display(odeplot_cmd, size = [550, 550]));
    catch:
        printf("Plotting failed. Ensure the initial conditions and ranges are correct.\n");
    end try;

    return Fsol;
  end proc:
 ####################    
end module:




 

true stands for using DataFrame
false : Error, (in odegeniter) Invalid combination of solve_all and range.

with(odegenerator);

[odegeniter, odegenman]

(1.1)

differential_eq:= diff(y(t), t) = sin(t)/'a__0' + y(t)/'a__1' + y(t)^2/'a__2' + exp(-t)/'b__0' + sinh(-t)/'b__1';
V := {0, 1};

diff(y(t), t) = sin(t)/a__0+y(t)/a__1+y(t)^2/a__2+exp(-t)/b__0-sinh(t)/b__1

 

{0, 1}

(1.2)

odegeniter(V, t, y, differential_eq, true, 0);# all DataFrame rows, using 0

Generating full DataFrame...

 

DataFrame(_rtable[36893489634290664740], rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32], columns = [Row, a__0, a__1, a__2, b__0, b__1, Equation, Solution])

(1.3)

odegeniter(V, t, y, differential_eq, true, 2);# a row in DataFrame, using 2 as rownumber ( check in full Dataframe)

 

Retrieving row 2 from DataFrame...

 

DataFrame(Vector[row](8, {(1) = 2, (2) = 0, (3) = 0, (4) = 0, (5) = 0, (6) = 1, (7) = diff(y(t), t) = -sinh(t), (8) = -cosh(t)+_C1}), rows = [1], columns = [Row, a__0, a__1, a__2, b__0, b__1, Equation, Solution])

(1.4)

odegeniter(V, t, y, differential_eq, true, 2..5);# a range of rows in DataFrame ( check in full Dataframe)

Retrieving rows 2 .. 5 from DataFrame...

 

DataFrame(Matrix(4, 8, {(1, 1) = 2, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 1, (1, 7) = diff(y(t), t) = -sinh(t), (1, 8) = -cosh(t)+_C1, (2, 1) = 3, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 1, (2, 6) = 0, (2, 7) = diff(y(t), t) = exp(-t), (2, 8) = -exp(-t)+_C1, (3, 1) = 4, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = 1, (3, 6) = 1, (3, 7) = diff(y(t), t) = exp(-t)-sinh(t), (3, 8) = -exp(-t)-cosh(t)+_C1, (4, 1) = 5, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1, (4, 5) = 0, (4, 6) = 0, (4, 7) = diff(y(t), t) = y(t)^2, (4, 8) = 1/(-t+_C1)}), rows = [1, 2, 3, 4], columns = [Row, a__0, a__1, a__2, b__0, b__1, Equation, Solution])

(1.5)

Now using odegenman for plotting a fieldplot from the differential eqation for a rownumber from the DataFrame

V := {0, 1};
differential_eq := diff(y(t), t) = sin(t)/'a__0' + y(t)/'a__1' + y(t)^2/'a__2' + exp(-t)/'b__0' + sinh(-t)/'b__1';
trange := 0..5;
yrange := -10..10;
initial_conditions := [[y(0) = 1], [y(0) = -1], [y(0) = 2]];# using 3 initial conditions
odegenman(V, t, y, differential_eq, [1, 1, 1, 1, 1], trange, yrange, initial_conditions);

{0, 1}

 

diff(y(t), t) = sin(t)/a__0+y(t)/a__1+y(t)^2/a__2+exp(-t)/b__0-sinh(t)/b__1

 

0 .. 5

 

-10 .. 10

 

[[y(0) = 1], [y(0) = -1], [y(0) = 2]]

 

The corresponding row number is: 32
The simplified ODE with the given coefficients is:

 

 

diff(y(t), t) = sin(t)+y(t)+y(t)^2+exp(-t)-sinh(t), [_Riccati]

 

Attempting to solve symbolically...
No explicit symbolic solution found for the differential equation. A DEplot will be generated numerically.
Generating DE plot for the differential equation...

 

 

"No explicit solution (analytically)."

(1.6)

lest take row 0 : y' = C , row 1 has 5 zeroes to fill in list in command

#odegenman(V, t, y, differential_eq, [1, 1, 1, 1, 1], trange, yrange, initial_conditions);# example of 5 ones in list is last rownumber of 32 rows for V := {0, 1};

odegenman(V, t, y, differential_eq, [0, 0, 0, 0, 0], trange, yrange, initial_conditions);

The corresponding row number is: 1
The simplified ODE with the given coefficients is:

 

 

diff(y(t), t) = 0, [_quadrature]

 

Attempting to solve symbolically...
Explicit symbolic solution found:

 

c__1

 

Generating DE plot for the differential equation...

 

 

c__1

(1.7)

Is correct

V := {0, 1};
differential_eq := diff(y(t), t) = 'a__0'*(y(t))^2 + 'b__0'* t^k;# special Riccati equation , k is an arbititrary number

{0, 1}

 

diff(y(t), t) = a__0*y(t)^2+b__0*t^k

(1.8)

odegeniter(V, t, y, differential_eq, true, 0);#, a0 = 1 and b0 = 1 , there is a overlap of rows  

Generating full DataFrame...

 

DataFrame(_rtable[36893489634206659876], rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32], columns = [Row, a__0, a__1, a__2, b__0, b__1, Equation, Solution])

(1.9)

odegeniter(V, t, y, differential_eq, true, 19);# row 19 gives the general solution, but using row 32 is always correct

Retrieving row 19 from DataFrame...

 

DataFrame(Vector[row](8, {(1) = 19, (2) = 1, (3) = 0, (4) = 0, (5) = 1, (6) = 0, (7) = diff(y(t), t) = y(t)^2+t^k, (8) = (BesselJ((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)*_C1+BesselY((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)-_C1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))-BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2)))/(t*(_C1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))+BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2))))}), rows = [1], columns = [Row, a__0, a__1, a__2, b__0, b__1, Equation, Solution])

(1.10)

now what is dfieldplot of this?

 

V := {0, 1};
differential_eq := diff(y(t), t) = 'a__0'*(y(t))^2 + 'b__0'* t^k;
trange := 0..5;
yrange := -10..10;
initial_conditions := [[y(0) = 1], [y(0) = -1], [y(0) = 2]];# using 3 initial conditions differential_eq := diff(y(t), t) = 'a__0'*(y(t))^2 + 'b__0'* t^k;

{0, 1}

 

diff(y(t), t) = a__0*y(t)^2+b__0*t^k

 

0 .. 5

 

-10 .. 10

 

[[y(0) = 1], [y(0) = -1], [y(0) = 2]]

(1.11)

odegenman(V, t, y, differential_eq, [1, 0, 0, 1, 0], trange, yrange, initial_conditions);#rownumber 19

The corresponding row number is: 19
The simplified ODE with the given coefficients is:

 

 

diff(y(t), t) = y(t)^2+t^k, [[_Riccati, _special]]

 

Attempting to solve symbolically...
Explicit symbolic solution found:

 

(BesselJ((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)*c__1+BesselY((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)-c__1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))-BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2)))/(t*(c__1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))+BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2))))

 

Generating DE plot for the differential equation...
Plotting failed. Ensure the initial conditions and ranges are correct.

 

(BesselJ((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)*c__1+BesselY((3+k)/(k+2), 2*t^((1/2)*k+1)/(k+2))*t^((1/2)*k+1)-c__1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))-BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2)))/(t*(c__1*BesselJ(1/(k+2), 2*t^((1/2)*k+1)/(k+2))+BesselY(1/(k+2), 2*t^((1/2)*k+1)/(k+2))))

(1.12)

How to get a fieldplot for this DE : "(&DifferentialD;)/(&DifferentialD;t) y(t)=(y(t))^2+t^k,[[_Riccati,_special]], "try to find information about this Bessel functions ?

?odeadvisor ;

?special functions;

?FunctionAdvisor;

FunctionAdvisor(Bessel, quiet);

[AiryAi, AiryBi, BesselI, BesselJ, BesselK, BesselY, HankelH1, HankelH2, KelvinBei, KelvinBer, KelvinHei, KelvinHer, KelvinKei, KelvinKer]

(1.13)

FunctionAdvisor(BesselJ, quiet);

FunctionAdvisor(BesselY, quiet);

 

 


 

Download module_odegeniter_odegenman.mw

# Eerste expressie definiëren
expr1 := (3*q*B[1]^2*A[1]*sin(W) + 3*q*B[1]*A[1]^2*cos(W) + 6*q*B[1]*A[1]*A[0])*sin(W)*cos(W)
         + q*A[1]^3*cos(W)^3 + 3*q*A[1]^2*cos(W)^2*A[0] 
         + (3*q*A[0]^2*A[1] + p*A[1] - s*A[1])*cos(W) 
         + q*B[1]^3*sin(W)^3 + 3*q*B[1]^2*sin(W)^2*A[0] 
         + (3*q*A[0]^2*B[1] + p*B[1] - s*B[1])*sin(W) 
         + q*A[0]^3 + p*A[0] - s*A[0]:

# Tweede expressie definiëren
expr2 := (A[1]*cos(W) + B[1]*sin(W) + A[0])*(q*A[1]^2*cos(W)^2 
         + 2*q*A[1]*(B[1]*sin(W) + A[0])*cos(W) 
         + q*B[1]^2*sin(W)^2 + 2*q*A[0]*B[1]*sin(W) 
         + q*A[0]^2 + p - s):

# Vereenvoudig het verschil om te controleren op gelijkheid
check_equiv := simplify(expr1 - expr2);

# Controleer of het verschil gelijk is aan nul
is_zero := evalb(check_equiv = 0);
is_zero;

 

@dharr , thanks for the solution, yes an error I have seen several times and thought I was going to solve it with with (package) but apparently that is not the right way for a procedure.
Why not, that's another specialist question....  

Error, (in Odegenerator) `DEtools` is not a module or member
Seems that uses not accept DEtools ?

@Carl Love , Thanks for correction!
It creeps in anyway ...

@WD0HHU 
Yes , the procedure can now calculate iteratively or manually.
In both calculations the odeadvisor has to determine the type of ode .
For iterative it is correct, but for manual I think not yet ,but not a big issue to solve

First 22 23 24 25 26 27 28 Last Page 24 of 80