| |
3.1 Diffusion in 1D
|
| |
https://www.12000.org/my_notes/pde_in_CAS/maple_2026_1_and_mma_15/indexsubsection156.htm#x181-1800003.1.1
| > |
restart;
HeatPDE := module()
option package;
uses plots, plottools, PDEtools;
export
Problem,
Solution,
ShowProblem,
AnalyzeProblem,
PlotTitle,
PDEPlot,
SolveProblem,
ShowSolution,
RunProblem;
(* -----------------------------------------------------------------
Probleemdefinitie
----------------------------------------------------------------- *)
Problem := proc()
module()
option object;
export
Title,
PDE,
BC,
IC,
Domain,
PDEType,
BCType,
DomainType,
ICType,
Assumptions;
end module;
end proc;
(* -----------------------------------------------------------------
Oplossingsobject
----------------------------------------------------------------- *)
Solution := proc()
module()
option object;
export
Solution,
Method,
MapleCall,
Verified,
CPUTime,
Warnings;
end module;
end proc;
(* -----------------------------------------------------------------
Toon probleemgegevens
----------------------------------------------------------------- *)
ShowProblem := proc(P)
printf("Titel: %a\n", P:-Title);
printf("PDE : %a\n", P:-PDE);
printf("BC : %a\n", P:-BC);
printf("IC : %a\n", P:-IC);
printf("Domein: %a\n", P:-Domain);
if assigned(P:-Assumptions) then
printf("Aannames: %a\n", P:-Assumptions);
end if;
NULL;
end proc;
(* -----------------------------------------------------------------
Analyse
----------------------------------------------------------------- *)
AnalyzeProblem := proc(P)
local R, ICrhs;
R := rhs(P:-PDE);
if has(R, diff(u(x,t), x$2)) then
P:-PDEType := "Diffusie";
else
P:-PDEType := "Onbekend";
end if;
if type(P:-BC, list) and nops(P:-BC) = 2 then
if has(lhs(P:-BC[1]), diff) or has(lhs(P:-BC[1]), D) or
has(lhs(P:-BC[2]), diff) or has(lhs(P:-BC[2]), D) then
P:-BCType := "Neumann-randvoorwaarden";
else
if rhs(P:-BC[1]) = 0 and rhs(P:-BC[2]) = 0 then
P:-BCType := "Dirichlet-randvoorwaarden (homogeen)";
else
P:-BCType := "Dirichlet-randvoorwaarden (niet-homogeen)";
end if;
end if;
else
P:-BCType := "Algemene randvoorwaarden";
end if;
P:-DomainType := "Eindig interval";
ICrhs := rhs(P:-IC);
if type(ICrhs, 'function') or has(ICrhs, function) then
P:-ICType := "Algemene functie";
else
P:-ICType := "Constante of eenvoudige uitdrukking";
end if;
NULL;
end proc;
(* -----------------------------------------------------------------
Titel voor de plot – met PDEtools:-declare voor mooie notatie
----------------------------------------------------------------- *)
PlotTitle := proc(P)
local u, x, t, k, L;
# declareer u(x,t) met afgeleide-notatie (u_t, u_xx)
PDEtools:-declare(u(x,t), prime=t);
# Gebruik de opgemaakte uitdrukkingen
return typeset(P:-IC, "\n", P:-PDE);
end proc;
(* -----------------------------------------------------------------
Schematische plot van het probleem
----------------------------------------------------------------- *)
PDEPlot := proc(P)
local ttl, bc1_str, bc2_str, Lval;
AnalyzeProblem(P);
ttl := PlotTitle(P);
bc1_str := convert(P:-BC[1], string);
bc2_str := convert(P:-BC[2], string);
# Haal de rechtergrens uit Domain, of gebruik 'L' als symbool
if type(P:-Domain, list) and nops(P:-Domain) = 2 then
Lval := P:-Domain[2];
else
Lval := 'L';
end if;
plots:-display(
plottools:-rectangle([0,-1], [10,1], color=white, linestyle=solid),
plottools:-line([2,0], [8,0], thickness=3, color=black),
plottools:-point([2,0], symbol=solidcircle, symbolsize=16, color=red),
plottools:-point([8,0], symbol=solidcircle, symbolsize=16, color=red),
plots:-textplot([2, -0.3, bc1_str], align={above, right}, font=[TIMES,12]),
plots:-textplot([8, -0.3, bc2_str], align={above, left}, font=[TIMES,12]),
plots:-textplot([2, -0.7, P:-BCType], align={above, right}, font=[TIMES,10, ITALIC]),
plots:-textplot([8, -0.7, P:-BCType], align={above, left}, font=[TIMES,10, ITALIC]),
plots:-textplot([2, 0.15, "0"], align={below}, font=[TIMES,12]),
plots:-textplot([8, 0.15, sprintf("%a", Lval)], align={below}, font=[TIMES,12]),
title = ttl,
titlefont = [TIMES, BOLD, 14],
axes = none,
size = [900, 300],
scaling = constrained
);
end proc;
(* -----------------------------------------------------------------
Oplossen met pdsolve
----------------------------------------------------------------- *)
SolveProblem := proc(P)
local eqs, sol, S;
eqs := [P:-PDE, P:-IC, op(P:-BC)];
if assigned(P:-Assumptions) then
sol := pdsolve(eqs, u(x,t), output=realtime) assuming op(P:-Assumptions);
else
sol := pdsolve(eqs, u(x,t), output=realtime);
end if;
S := Solution();
S:-Solution := sol;
S:-Method := "pdsolve";
S:-MapleCall:= "pdsolve(... output=realtime)";
S:-Verified := "Niet geverifieerd";
S:-CPUTime := "Niet gemeten";
S:-Warnings := "";
return S;
end proc;
(* -----------------------------------------------------------------
Toon oplossing
----------------------------------------------------------------- *)
ShowSolution := proc(S)
print(S:-Solution);
NULL;
end proc;
(* -----------------------------------------------------------------
Volledige run – plot wordt zichtbaar
----------------------------------------------------------------- *)
RunProblem := proc(P)
local S;
ShowProblem(P);
AnalyzeProblem(P);
print(PDEPlot(P));
S := SolveProblem(P);
ShowSolution(S);
return S;
end proc;
end module:
|
| > |
with(HeatPDE):
P := Problem();
P:-Title := "Problem 151 - constante beginvoorwaarde";
P:-PDE := diff(u(x,t), t) = (1/100)*diff(u(x,t), x$2);
P:-BC := [u(0,t)=0, u(10,t)=0];
P:-IC := u(x,0)=100;
P:-Domain:= [0,10];
P:-Assumptions := [];
S := RunProblem(P);
# 3D‑plot: standaard tot t=5
PlotSolution(S, P);
# Met fijnere resolutie en andere eindtijd
PlotSolution(S, P, T=10, gridpts=100);
|
|
Titel: "Problem 151 - constante beginvoorwaarde"
PDE : diff(u(x,t),t) = 1/100*diff(diff(u(x,t),x),x)
BC : [u(0,t) = 0, u(10,t) = 0]
IC : u(x,0) = 100
Domein: [0, 10]
Aannames: []
|
|
|
|
(1.1) |
|
| |
probleem 150
|
| |
| > |
with(HeatPDE);
P := Problem():
P:-Title := "Problem 150":
P:-PDE := diff(u(x,t), t) = k * diff(u(x,t), x$2):
P:-BC := [u(0,t) = 0, u(L,t) = 0]:
P:-IC := u(x,0) = f(x):
P:-Domain:= [0, L]:
P:-Assumptions := [k > 0, L > 0]:
# Voer alles uit
S := RunProblem(P):
# Nu kun je met P en S verder werken
printf("Gebruikte methode: %a\n", S:-Method);
oplossing := S:-Solution;
|
|
Titel: "Problem 150"
PDE : diff(u(x,t),t) = k*diff(diff(u(x,t),x),x)
BC : [u(0,t) = 0, u(L,t) = 0]
IC : u(x,0) = f(x)
Domein: [0, L]
Aannames: [0 < k, 0 < L]
|
|
|
Gebruikte methode: "pdsolve"
|
|
|
|
(2.1) |
|
| |
probleem 151
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE);
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 151 - Warmtegeleiding met constante beginvoorwaarde":
P:-PDE := diff(u(x,t), t) = (1/100) * diff(u(x,t), x$2): # k = 1/100
P:-BC := [u(0,t) = 0, u(10,t) = 0]: # L = 10
P:-IC := u(x,0) = 100: # f(x) = 100
P:-Domain:= [0, 10]: # L = 10
P:-Assumptions := []: # Geen extra aannames nodig
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 151 - Warmtegeleiding met constante beginvoorwaarde"
PDE : diff(u(x,t),t) = 1/100*diff(diff(u(x,t),x),x)
BC : [u(0,t) = 0, u(10,t) = 0]
IC : u(x,0) = 100
Domein: [0, 10]
Aannames: []
|
|
|
|
(3.1) |
|
| |
probleem 152
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE):
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 152 - Beginvoorwaarde u = x(1-x)":
P:-PDE := diff(u(x,t), t) = (1/100) * diff(u(x,t), x$2): # k = 1/100
P:-BC := [u(0,t) = 0, u(1,t) = 0]: # L = 1
P:-IC := u(x,0) = x*(1-x): # f(x) = x(1-x)
P:-Domain:= [0, 1]: # L = 1
P:-Assumptions := []: # Geen extra aannames
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 152 - Beginvoorwaarde u = x(1-x)"
PDE : diff(u(x,t),t) = 1/100*diff(diff(u(x,t),x),x)
BC : [u(0,t) = 0, u(1,t) = 0]
IC : u(x,0) = x*(1-x)
Domein: [0, 1]
Aannames: []
|
|
|
|
(4.1) |
|
| |
probleem 153
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE):
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 153 - Haberman 2.3.3 (a)":
P:-PDE := diff(u(x,t), t) = k * diff(u(x,t), x$2): # algemene diffusiecoëfficiënt k
P:-BC := [u(0,t) = 0, u(L,t) = 0]: # homogene Dirichlet
P:-IC := u(x,0) = 6 * sin(9*Pi*x/L): # specifieke beginvoorwaarde
P:-Domain:= [0, L]: # lengte L (symbool)
P:-Assumptions := [k > 0, L > 0]: # fysische aannames voor pdsolve
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 153 - Haberman 2.3.3 (a)"
PDE : diff(u(x,t),t) = k*diff(diff(u(x,t),x),x)
BC : [u(0,t) = 0, u(L,t) = 0]
IC : u(x,0) = 6*sin(9*Pi*x/L)
Domein: [0, L]
Aannames: [0 < k, 0 < L]
|
|
|
|
(5.1) |
|
| |
probleem 160
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE):
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 160 - Warmte met bronterm Q(x) (algemeen)":
P:-PDE := diff(u(x,t), t) = k * diff(u(x,t), x$2) + Q(x): # inhomogene PDE
P:-BC := [u(0,t) = 0, u(L,t) = 0]: # homogene Dirichlet
P:-IC := u(x,0) = f(x): # algemene beginvoorwaarde
P:-Domain:= [0, L]: # lengte L (symbool)
P:-Assumptions := [k > 0, L > 0]: # fysische aannames
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 160 - Warmte met bronterm Q(x) (algemeen)"
PDE : diff(u(x,t),t) = k*diff(diff(u(x,t),x),x)+Q(x)
BC : [u(0,t) = 0, u(L,t) = 0]
IC : u(x,0) = f(x)
Domein: [0, L]
Aannames: [0 < k, 0 < L]
|
|
|

|
(6.1) |
|
| |
problem 196
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE):
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 196 - Gemengde (Robin) randvoorwaarden":
P:-PDE := diff(u(x,t), t) = k * diff(u(x,t), x$2);
P:-BC := [
D[1](u)(0,t) + u(0,t) = 0, # Robin BC aan linkerzijde
D[1](u)(L,t) + u(L,t) = 0 # Robin BC aan rechterzijde
]:
P:-IC := u(x,0) = f(x):
P:-Domain:= [0, L]:
P:-Assumptions := [k > 0, L > 0]:
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 196 - Gemengde (Robin) randvoorwaarden"
PDE : diff(u(x,t),t) = k*diff(diff(u(x,t),x),x)
BC : [D[1](u)(0,t)+u(0,t) = 0, D[1](u)(L,t)+u(L,t) = 0]
IC : u(x,0) = f(x)
Domein: [0, L]
Aannames: [0 < k, 0 < L]
|
|
|
|
(7.1) |
|
| |
problem 167
|
| |
| > |
# 1. Laad de module (als die nog niet geladen is)
with(HeatPDE):
# 2. Maak een nieuw probleemobject
P := Problem():
# 3. Vul de gegevens in volgens de opgave
P:-Title := "Problem 167 - Variabele coëfficiënten: u_t = x^2 u_xx + x u_x":
P:-PDE := diff(u(x,t), t) = x^2 * diff(u(x,t), x$2) + x * diff(u(x,t), x):
P:-BC := [u(1,t) = 0, u(b,t) = 0]:
P:-IC := u(x,0) = f(x):
P:-Domain:= [1, b]:
P:-Assumptions := [b > 1]: # x in (1,b), dus positief, en b>1
# 4. Voer de volledige analyse, plot en oplossing uit
S := RunProblem(P):
|
|
Titel: "Problem 167 - Variabele coëfficiënten: u_t = x^2 u_xx + x u_x"
PDE : diff(u(x,t),t) = x^2*diff(diff(u(x,t),x),x)+x*diff(u(x,t),x)
BC : [u(1,t) = 0, u(b,t) = 0]
IC : u(x,0) = f(x)
Domein: [1, b]
Aannames: [1 < b]
|
|
|
|
(8.1) |
|
| |
Voorbeeld: Problem 200 – Warmteflux aan één uiteinde
|
| |
| > |
with(HeatPDE):
# ===================================================================
# 1. Definieer het probleem
# ===================================================================
P := Problem():
P:-Title := "Problem 200 - Warmteflux aan linkerzijde":
P:-PDE := diff(u(x,t), t) = k * diff(u(x,t), x$2):
# Randvoorwaarden:
# -k * u_x(0,t) = q0 (warmteflux) => u_x(0,t) = -q0/k
# u(L,t) = 0
P:-BC := [D[1](u)(0,t) = -q0/k, u(L,t) = 0]:
# Beginvoorwaarde: staaf is aanvankelijk op temperatuur 0
P:-IC := u(x,0) = 0:
P:-Domain:= [0, L]:
P:-Assumptions := [k > 0, L > 0, q0 > 0]:
# ===================================================================
# 2. Los op en toon resultaten
# ===================================================================
S := RunProblem(P):
|
|
Titel: "Problem 200 - Warmteflux aan linkerzijde"
PDE : diff(u(x,t),t) = k*diff(diff(u(x,t),x),x)
BC : [D[1](u)(0,t) = -q0/k, u(L,t) = 0]
IC : u(x,0) = 0
Domein: [0, L]
Aannames: [0 < k, 0 < L, 0 < q0]
|
|
|
|
(9.1) |
|
|