janhardo

695 Reputation

12 Badges

11 years, 39 days

MaplePrimes Activity


These are answers submitted by janhardo

wrong code 

Depends on the physical context

restart;
with(Physics):

# 1. Setup and check
# Set default coordinates
Setup(coordinates = [r, theta]);

# Define a metric tensor
Define(g_[~mu, ~nu] = diag(-1, 1, 1, 1)); # Minkowski metric

# Diagnostic test: check a simple case without inert differentials
eq_simple := g_[~mu, ~nu] * v[~mu] * v[~nu]:
SumOverRepeatedIndices(eq_simple); # Expect a contracted result

# 2. Working with inert differentials
# Define the equation with differentials
eq_inert := g_[~mu, ~nu] * Diff(w(r, theta), ~mu) * Diff(w(r, theta), ~nu):

# Diagnostic test: check indices
Check(eq_inert, all);

# Attempt to contract over repeated indices
result_inert := SumOverRepeatedIndices(eq_inert);

# Output the results
print("Result for simple vectors without inertia:");
print(SumOverRepeatedIndices(eq_simple));
print("Result for equation with inert differentials:");
print(result_inert);

# 3. Check various settings
# Attempt explicit metric contraction
Physics:-Simplify(result_inert);
restart;
with(Physics):
Physics:-Setup(inertdiffs = true);
g_[[5, 29, 1]]; 
eq1 := g_[~mu, ~nu] * Diff(w(r, theta), mu) * Diff(w(r, theta), nu);
Physics:-Contract(eq1);
Physics:-Check(eq1, all);
with(plots):

# Create the vertical line in segments with labels
L1 := plottools:-line([0, 0], [0, 0.9], color="blue"):
L2 := plottools:-line([0, 1.1], [0, 1.9], color="blue"):
L3 := plottools:-line([0, 2.1], [0, 3], color="blue"):

# Create the disks without transparency
c1 := plottools:-disk([0, 1], 0.1, color="red"):
c2 := plottools:-disk([0, 2], 0.1, color="green"):

# Add labels for each line segment
label1 := plots:-textplot([0.1, 0.45, "Segment 1"], align={left}):
label2 := plots:-textplot([0.1, 1.5, "Segment 2"], align={left}):
label3 := plots:-textplot([0.1, 2.5, "Segment 3"], align={left}):

# Combine the objects and display the plot
display([L1, L2, L3, c1, c2, label1, label2, label3], scaling=constrained, axes=none);

@salim-barzani 
First when you can solve it step by step a problem  , than it should be always possible to make a procedure from it 
Don't know if this makes sense too thi sprocedure 

restart;
with(inttrans):
with(PDEtools):
with(LinearAlgebra):               

undeclare(prime);

with(PDEtools);
declare();                

# Define a procedure that takes the ODE as input
SolveODEWithAdomian := proc(ode)
    local eq, eqs, u0, A, B, j, lap_sol, adomian_sol, final_sol, f, g, m;

    # Step 1: Initial conditions and function definitions
    u0 := (x, t) -> exp(x)*t;  # Define u0 as the base function
    A := Array(0..3);  # Array for Adomian polynomials A[j]
    B := Array(0..3);  # Array for Adomian polynomials B[j]

    # Functions representing the nonlinear terms
    f := u -> u^2;
    g := u -> diff(u, x)^2;

    # Step 2: Calculate the Adomian polynomials A[j] and B[j]
    for j from 0 to 3 do
        A[j] := subs(lambda=0, diff(f(seq(sum(lambda^i * u[i](x, t), i=0..20), m=1..2)), [lambda$j]) / j!);
        B[j] := subs(lambda=0, diff(g(seq(sum(lambda^i * u[i](x, t), i=0..20), m=1..2)), [lambda$j]) / j!);
    end do;

    # Step 3: Perform the Laplace transform of the ODE
    eqs := laplace(ode, t, s);

    # Step 4: Solve in the Laplace domain
    lap_sol := solve({eqs}, {laplace(u(x, t), t, s)});

    # Step 5: Substitute initial conditions for the solution in the Laplace domain
    lap_sol := subs({u(x, 0) = 0, D[2](u)(x, 0) = exp(x)}, lap_sol);

    # Step 6: Transform back to the time domain with the inverse Laplace transform
    adomian_sol := Array(0..3);  # Array to store approximate terms
    for j from 0 to 3 do
        # Define each term of the Adomian solution with inverse Laplace of A[j] and B[j]
        adomian_sol[j] := -invlaplace(1/(s^2) * (A[j] + B[j]), s, t);
    end do;

    # Step 7: Sum all terms of the Adomian solution to obtain the final solution
    final_sol := u0(x, t) + add(adomian_sol[j], j=0..3);

    # Return the result
    return simplify(final_sol);
end proc;

# Define the ODE with the known solution
ode := diff(u(x, t), t $ 2) + u(x, t)^2 - diff(u(x, t), x)^2 = 0;

# Call the SolveODEWithAdomian procedure with the ODE as input
result := SolveODEWithAdomian(ode);

# Print the approximate solution
simplify(result);

wrong example 

# Set parameters
D := 1: # Set an appropriate value for the bending stiffness
rho := 1: # Set an appropriate value for the density
h := 0.1: # Set an appropriate value for the thickness

# Define the differential equation
pde := D*diff(w(x, y, t), x$2) + D*diff(w(x, y, t), y$2) + rho*h*diff(w(x, y, t), t$2) = 0;

# Specify initial and boundary conditions
ic := w(x, y, 0) = sin(Pi*x)*sin(Pi*y), D[1, t](w(x, y, t)) = 0; # initial displacement and velocity
bc := w(0, y, t) = 0, w(1, y, t) = 0, w(x, 0, t) = 0, w(x, 1, t) = 0; # boundary conditions

# Solve and visualize
sol := pdsolve([pde, ic, bc], w(x, y, t), numeric);

# Plot the vibration
plots:-animate3d(subs(sol, w(x, y, t)), x = 0 .. 1, y = 0 .. 1, t = 0 .. 1, frames = 30);
As example , you can get all sorts of functions.

f := z -> z * hypergeom([1, 1], [2], -z);

f := proc (z) options operator, arrow; z*hypergeom([1, 1], [2], 

   -z) end proc


f := z -> z * hypergeom([1, 1], [2], -z):
simplify(f(z));

                           ln(1 + z)

 

Now as procedure

restart;

solveODE := proc(data)
    local the_result, ode, current_ode, sol, item;
    
    # Create an empty array to store results
    the_result := Array(1..0):
    # Header for the table
    the_result ,= [P, Q, R, "current ode", "solution"]:
    
    # Differential equation
    ode := diff(F(xi), xi)^2 = P * F(xi)^4 + Q * F(xi)^2 + R:
    
    # Iterate through each set of P, Q, R in data
    for item in data do
        current_ode := limit(eval(ode, item), m = 1, 'left'):
        sol := [dsolve(current_ode)]:
        the_result ,= [rhs(item[1]), rhs(item[2]), rhs(item[3]), current_ode, sol]:        
    od:
    
    # Convert the results to a list and display as a table
    the_result := convert(the_result, listlist):
    return DocumentTools:-Tabulate(the_result, weights = [10, 20, 20, 45, 45], width = 60):
end proc:

# Run the procedure with the given data
data := [
    [P = m^2, Q = -(1 + m^2), R = 1],
    [P = 1, Q = -(1 + m^2), R = m^2],
    [P = -m^2, Q = 2 * m^2 - 1, R = 1 - m^2],
    [P = 1, Q = 2 * m^2 - 1, R = -m^2 * (1 - m^2)],
    [P = 1/4, Q = (m^2 - 2) / 2, R = m^2 / 4],
    [P = m^2 / 4, Q = (m^2 - 2) / 2, R = m^2 / 4]
]:

solveODE(data);

I have here an example of a table with a complex function, in which the Explore command is inserted in the table cell.
An absolute complex plot is not attached 
It's more of a draft worksheet to get some ideas 

mprimes_parameter_13-10-2024-salim.mw

@Susana30 
Yes, you can copy it from here. 
To get floating point numbers( decimal)  , add a  period with zero ( i did for  2 ) for one intersection point  in Cartesian coordinates.
 

theta_values := [2.0*Pi/3, 4*Pi/3]:  # The two theta values for the intersection points
with(plots):

# Exercise: Calculate the intersection points in Cartesian coordinates
# Step 1: Solve the equation to find theta
theta_values := [2.0*Pi/3, 4*Pi/3]:  # The two theta values for the intersection points

# Step 2: Calculate the radius values (r) for the found angles
r_circle := map(t -> -6*cos(t), theta_values):  # For the circle

# Step 3: Calculate the Cartesian coordinates for the two intersection points
points_cartesian := [
    [r_circle[1]*cos(theta_values[1]), r_circle[1]*sin(theta_values[1])],  # Intersection point 1
    [r_circle[2]*cos(theta_values[2]), r_circle[2]*sin(theta_values[2])]   # Intersection point 2
]:

# Display the calculated intersection points in Cartesian coordinates
points_cartesian;  # This will display the two points as (x, y)

# Expected output:
# [-1.5, 2.598], [-1.5, -2.598]

# Step 4: Plot the circle and cardioid in polar coordinates
p2 := polarplot([-6*cos(theta), 2 - 2*cos(theta)], theta = 0..2*Pi, color = [green, purple], legend = ["Circle", "Cardioid"]):

# Step 5: Plot the intersection points in Cartesian coordinates
intersection_points := pointplot(points_cartesian, symbol=circle, color=red, symbolsize=15):

# Step 6: Combine the plots
display(p2, intersection_points);

 


 

# Define n, the size of the matrix (n+1 x n+1)
n := 3:  # Example value, you can change it

# Initialize the matrix P
P := Matrix(n+1, n+1):

# Define the binomial coefficient function for clarity
binom := (a, b) -> binomial(a, b):

# Define the entry formula for p_kr
for k from 0 to n do
    for r from 0 to n do
        P[k+1, r+1] := (2*r + 1) * add((-1)^j * binom(n-k, j) * (n+k+j+1)/(k+j+1) *
            add((-1)^l * binom(n-r, l) * (n+r+l+1)/(k+r+l+j+2), l=0..n-r), j=0..n-k);
    end do;
end do;

# Display the matrix P
P;

Matrix(4, 4, {(1, 1) = 9/32, (1, 2) = 73/160, (1, 3) = 29/32, (1, 4) = 1477/160, (2, 1) = 17/480, (2, 2) = 3/32, (2, 3) = 25/96, (2, 4) = 301/96, (3, 1) = 1/160, (3, 2) = 1/32, (3, 3) = 5/32, (3, 4) = 105/32, (4, 1) = -1/160, (4, 2) = -1/32, (4, 3) = -5/32, (4, 4) = 343/32})

(1)

variant  2

# Definieer n (de matrixorde)
n := 3:  # Voorbeeldwaarde

# Initialiseer de matrix P
P := Matrix(n+1, n+1):

# Verkorte notatie voor binomiale coëfficiënt
binom := (a, b) -> binomial(a, b):

# Constructie van de matrixentry-formule met somnotatie
for k from 0 to n do
    for r from 0 to n do
        P[k+1, r+1] := (2*r + 1) * add(
            (-1)^j * binom(n-k, j) * (n+k+j+1) / (k+j+1) *
            add(
                (-1)^l * binom(n-r, l) * (n+r+l+1) / (k+r+l+j+2),
                l=0..n-r),
            j=0..n-k);
    end do;
end do;

# Toon de matrix P
P;

Matrix(4, 4, {(1, 1) = 9/32, (1, 2) = 73/160, (1, 3) = 29/32, (1, 4) = 1477/160, (2, 1) = 17/480, (2, 2) = 3/32, (2, 3) = 25/96, (2, 4) = 301/96, (3, 1) = 1/160, (3, 2) = 1/32, (3, 3) = 5/32, (3, 4) = 105/32, (4, 1) = -1/160, (4, 2) = -1/32, (4, 3) = -5/32, (4, 4) = 343/32})

(2)

 

variant 3

n := 3;  # Define the order of the matrix (replace 5 with your desired order)

# Define binomial coefficients
binom := (a, b) -> binomial(a, b);

# Define p_kr elements
p_kr := (k, r) -> (2*r+1) * sum((-1)^j * binom(n-k, j) * (n+k+j+1)/(k+j+1) *
                       sum((-1)^l * binom(n-r, l) * (n+r+l+1)/(k+r+l+j+2), l=0..n-r), j=0..n-k);

# Generate the matrix P
P := Matrix(n+1, n+1, (k, r) -> p_kr(k-1, r-1));  # Matrix indices in Maple start from 1, so adjust for 0-based indexing

# Display the matrix
#;

n := 3

 

binom := proc (a, b) options operator, arrow; binomial(a, b) end proc

 

p_kr := proc (k, r) options operator, arrow; (2*r+1)*(sum((-1)^j*binom(n-k, j)*(n+k+j+1)*(sum((-1)^l*binom(n-r, l)*(n+r+l+1)/(k+r+l+j+2), l = 0 .. n-r))/(k+j+1), j = 0 .. n-k)) end proc

 

Matrix(%id = 36893491146477614012)

(3)

n := infinity;  # Define the order of the matrix (replace 5 with your desired order)

# Define binomial coefficients
binom := (a, b) -> binomial(a, b);

# Define p_kr elements
p_kr := (k, r) -> (2*r+1) * sum((-1)^j * binom(n-k, j) * (n+k+j+1)/(k+j+1) *
                       sum((-1)^l * binom(n-r, l) * (n+r+l+1)/(k+r+l+j+2), l=0..n-r), j=0..n-k);

# Generate the matrix P
P := Matrix(n+1, n+1, (k, r) -> p_kr(k-1, r-1));  # Matrix indices in Maple start from 1, so adjust for 0-based indexing

# Display the matrix
#;

infinity

 

proc (a, b) options operator, arrow; binomial(a, b) end proc

 

proc (k, r) options operator, arrow; (2*r+1)*(sum((-1)^j*binom(n-k, j)*(n+k+j+1)*(sum((-1)^l*binom(n-r, l)*(n+r+l+1)/(k+r+l+j+2), l = 0 .. n-r))/(k+j+1), j = 0 .. n-k)) end proc

 

Error, (in Matrix) dimension parameters are required for this form of initializer

 

 


 

Download matrix_sommen_-maple_primes.mw

sol := dsolve(sys union ics, {x(t), y(t)}, numeric, method = rkf45, range = 0 .. 20000, maxfun = 10000000, output = listprocedure, abserr = 1e-12, relerr = 1e-12, stepsize = 0.001);

 

 


 

"maple.ini in users"

(1)

f:=(x,y)->3*x^3*exp(2*y)+x^2*y^2;

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

(2)

f__x:= D[1](f);

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

(3)

f__xx:=D[1,1](f);

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

(4)

f__x3:=D[1$3](f);

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

(5)

f__y:=D[2](f);

proc (x, y) options operator, arrow; 6*x^3*exp(2*y)+2*x^2*y end proc

(6)

f__yxx:=D[2,1,1](f);

proc (x, y) options operator, arrow; 36*x*exp(2*y)+4*y end proc

(7)

f__xy2x:=D[1,2$2,1](f);# f__xyyx:=D[1,2$2,1](f);

proc (x, y) options operator, arrow; 72*x*exp(2*y)+4 end proc

(8)

 


 

Download maple_primes_post_partiel_diff.mw

with(Student:-Calculus1)
infolevel[Student[Calculus1]] := 1

To get a idea , you can use Hint  from Rule package
If you are uncertain about which rule to apply next to a problem, ask for a hint.
Hint(Limit(-tanh(sqrt(2)*(a*x+b)),x=0));
Check one-sided limits separately
 

The output from the Hint command can always be used as the index to the Rule command.
Rule[[chain]](Diff(sin(x^2), x)); (see example Maple ) , how it goes further ?
 

I assume ax+ b that all variables are real numbers ?

1 2 3 4 5 6 Page 5 of 6