janhardo

700 Reputation

12 Badges

11 years, 43 days

MaplePrimes Activity


These are replies submitted by janhardo

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

restart;
params := {alpha = 1, gg = 0.1, k = 1, mu = 10, sigma = 5, w = 2};
M := 2*sqrt(-(gg*(gg*k*mu - 2*k*sigma)*k/(gg*sigma - 1) + k^2)/alpha)*exp((-(4*gg*k*w + 4*k^2 - sigma^2)*t/(gg*sigma - 1) + sigma*x)*I)/sinh(-2*k*x + (-gg*k*(4*gg*k*w + 4*k^2 - sigma^2)/(gg*sigma - 1) - 2*k*sigma)*t/(gg*sigma - 1));
Explore(plot3d([Re, Im](M), t = 0 .. 5, x = 0 .. 5, view = -100 .. 100, grid = [150, 150], color = [red, blue], style = surface, adaptmesh = false, size = [500, 500]), alpha = 0.1 .. 2.0, gg = 0.1 .. 0.3, w = 1 .. 5, mu = 1.0 .. 10.0, sigma = 1.0 .. 4.0, k = 1.0 .. 2.0, placement = right);

Explore example plot of complex valued function
Can be used for trying to get a explore plot with Wiener function 

@salim-barzani , there is some direction now , but did you succeed in your code to get this reduced pde form (ode)  ?
I did, but  now how to go further ..well it seems there is enough probably to find the right information for me  : handbooks and so on
i do have another solution to your problem try contact : AndreiD.Polyanin or
AlexeiI.Zhurov from Russia they are experts pdes and odes 

 pde

u(x,t) is pde value of U(z) and is plot from a ode , it all revolves about a reduceded pde , to solve this 
How to solve this non lineair complex valued third orde ode , right?

Another second way of defining pde with a table U 

with(PDEtools): 
declare(u(x,t)); 
U := diff_table(u(x,t));
interface(showassumed = 0); 
assume(k > 0);
PDE1 := I*U[t] + U[x,x] + k*abs(U[])^2*U[] = 0;
Sol1 := u(x,t) = C1*exp(I*(C2*x + (k*C1^2 - C2^2)*t + C3));
Test1 := pdetest(Sol1, PDE1); 
Test11 := simplify(evalc(Test1));
Sol2 := u(x,t) = A*sqrt(2/k)*(exp(I*B*x + I*(A^2 - B^2)*t + I*C1))/(cosh(A*x - 2*A*B*t + C2));
Test2 := pdetest(Sol2, PDE1); 
Test21 := simplify(evalc(Test2));# jd complexe getallen

a third way is : direct 

with(PDEtools):(u(x,y));
PDE1:=x*diff(u(x,y),y)-diff(u(x,y),x)=g(x)*u(x,y)^2;
Sol1:=pdsolve(PDE1);

pdetest(Sol1,PDE1);

a fourth way example is with declare 

with(PDEtools): declare(u(x,y)); # hier word declare gebruikt
PDE1:=u(x,y)*diff(u(x,y),y)=diff(u(x,y),x);
sysCh:=charstrip(PDE1,u(x,y)); funcs:=indets(sysCh,Function);
Sol1:=dsolve(sysCh,funcs,explicit);

As notation seems te be handier in this example an note how this is done 
with(PDEtools): with(plots): tr1:=x-c*t=z; tr2:={a=1,b=1,c=1}; # JD traveling wave 
Eq1:=u->diff(u,t)+a*u*diff(u,x)+b*diff(u,x$3)=0;
Eq2:=expand(Eq1(U(lhs(tr1)))); Eq3:=algsubs(tr1,Eq2);
Eq4:=map(convert,Eq3,diff); Eq5:=map(int,lhs(Eq4),z)-C1=0;
Eq6:=expand(Eq5*2*diff(U(z),z)); Eq7:=map(int,Eq6,z);
Eq8:=lhs(Eq7)=C2; Eq9:=subs({C1=0,C2=0},Eq8);
Sol1:=[dsolve(Eq9,U(z))]; Sol11:=subs(_C1=0,simplify(Sol1[2]));
Sol12:=convert(Sol11,sech); Sol2:=eval(subs(z=x-c*t,Sol11),tr2);
convert(Sol2,sech);
animate(plot,[rhs(Sol2),x=-20..20,color=blue],t=0..20,numpoints=100,
frames=50,thickness=2);
pdetest(u(x,t)=rhs(Sol2),subs(tr2,Eq1(u(x,t))));


your pde

Eq1 := u -> (diff(u, t, t) - c^2*diff(u, x, x))*I + diff(U(-t*tau + x)^2*u, t) - lambda*c*diff(U(-t*tau + x)^2*u, x) + 1/2*diff(u, t, x, x) - 1/2*epsilon*c*diff(u, x, x, x) = 0

First 15 16 17 18 19 20 21 Last Page 17 of 73