Hello everybody.
I am working on a heat equation of 1D heat equation and I was applying the DMD method on the numeric solution using DMDSVD() which gave me the following error DimensionMismatch("expected axes .
I have pasted my code with the topic so does anybody knoq how can I solve this error.
# rod Length
L = 0.5
Tf = 10000.0
# Thermal conductivity
λ = 45.0
# Specific heat capacity
c = 480.0
# Mass density
ρ = 7800.0
# Thermal diffusivity
α = λ/(c*ρ)
using SparseArrays
using Plots
using DifferentialEquations
using LinearAlgebra
# Number of grid elements
N = 101
# Finite discretization
Δx = L/(N-1)
# 1-dimensional grid
xspan = 0 : Δx : L
# Diffusion matrix
M = spdiagm(-1 => ones(N-1), 0 => -2*ones(N), 1 => ones(N-1));
#creat matrix M 5x5
Matrix(M)[1:5,1:5]
# First row
M[1,1] = M[1,2] = 0;
# Last row
M[end,end] = M[end,end-1] = 0;
# Heat Equation as ODE
function heat_eq(dθ, θ, p, t)
return dθ .= (1/Δx^2) * α * M * θ
end
#Initial conditions: θ(0) = m * (L * x - x^2)
function initial_data(x, params)
# α = params[1] # unused here
L = params[2]
m = params[3]
return m*( L * x - x^2)
end
# Initial heat distribution
θ₀ = zeros(N);
m = 50
amp = 50
# Parameters
param = [α, L, amp]
let
for i = 1 : length(xspan)
θ₀[i] = initial_data(xspan[i], param)
end
plot(xspan, θ₀, xlabel="Position X", ylabel="Temperature", legend=false)
end
# Upper limit of sampling time
ul = 0.5 * Δx^2 / α
# Sampling time
Δt = 0.8
# time discretization
tspan = (0.0, 1000.0)
# Solving the ODE
let
prob = ODEProblem( heat_eq, θ₀, tspan ) # ODE Problem
sol = solve(prob,Euler(),dt=Δt,progress=true, save_everystep=false,
save_start=true) # Solving the ODE
plot(xspan, sol.u[2], xlabel = "Position X", ylabel="Temperature", legend=false)
end
using DataDrivenDiffEq
Y = sol[:,:]
#plot(Y, legend = nothing)
DY = sol(sol.t, Val{1})[:,:]
approx_heat = ContinuousDataDrivenProblem(Y, DY)
#plot(approx_heat)
#mutable struct DMDSVD{T} <: DataDrivenDiffEq.AbstractKoopmanAlgorithm
#global res = solve(approx_heat, DMDSVD(0.0),digits =1)
#end
res = solve(approx_heat, DMDSVD(),digits =1)