Comparison PDE solve and \ mldivide
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Phineas
am 29 Sep. 2025
Bearbeitet: Walter Roberson
am 29 Sep. 2025
Hello all,
I have a problem and would like you thoughts on it. I guess I miss something in the definition of some matlab functions but can not find out where my error is.
Comparison of solve function with mldivide in a transient heat analysis gives different solutions.
Probably an missuse of the Nullspace transformation but did not find yet where??
I would really like to understand what I got wrong and would be thankfull for your comments.
Phineas Freak
%Following unified modelling approach:
clear all
%Geometry
shape_1=polyshape([-150, 150, 150, -150],[-150, -150, 150,150]);
BlockRaw= triangulation(shape_1);
BlockRaw=fegeometry(BlockRaw);
BlockRaw=extrude(BlockRaw,300);
BlockRaw=scale(BlockRaw, 1/1000); % [mm] to [m]
% Model
model=femodel(AnalysisType="ThermalTransient", Geometry= BlockRaw);
figure
pdegplot(model,FaceLabels="on",EdgeLabels="on")
model.MaterialProperties=materialProperties(ThermalConductivity=46.5, MassDensity=7800, SpecificHeat=.502);
% Initial Temperature
model.CellIC(1) = cellIC(Temperature=273+180);
%BC1
model.FaceLoad(3) = faceLoad(Heat=300);
% BC2
model.FaceBC(1) = faceBC(Temperature=200);
% BC 3
model.FaceLoad(6) = faceLoad(Heat=100);
% Coarse Mesh - exact result not important as comparison between methods
model = generateMesh(model, GeometricOrder='linear', Hmin=.05);
figure
pdemesh(model)
% Time Interval
dt=.25;
t_end=4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Builtin solver
ZylinderRes = solve(model, [0:dt:t_end]);
figure
pdeplot3D(ZylinderRes.Mesh,ColorMapData=ZylinderRes.Temperature(:,end))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% mldivide
state = struct('time', ZylinderRes.SolutionTimes(1), 'u', ZylinderRes.Temperature(:,1)');
FEMMatrix=assembleFEMatrices(model,state);
K = FEMMatrix.K;
M= FEMMatrix.M;
F = FEMMatrix.F;
H=FEMMatrix.H;
R=FEMMatrix.R;
G=FEMMatrix.G;
theta=1;
[B,Or]=pdenullorth(FEMMatrix.H);
ud=Or*((H*Or\R)); % Prüfung - Korrekt
U_=zeros(length(ud),17);
U_(:,1)=ZylinderRes.Temperature(:,1);
% Nullspace Dirichlet Transformation
Kc =B'*(theta*K + M/dt)*B;
dt_sum = 0;
for i=2:t_end/dt+1
dt_sum=dt_sum+dt;
Fc=B'*((F+G) - K*ud + ( M/dt - (1-theta)*K )*U_(:,i-1)) ;
U_(:,i) = B* (Kc \ Fc ) + ud;
end
figure
pdeplot3D(ZylinderRes.Mesh,ColorMapData=U_(:,end))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Comparison: Missmatch
figure
plot(ZylinderRes.Temperature(1:400,4)-U_(1:400,4),'b-')
3 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 29 Sep. 2025
model.MaterialProperties(ThermalConductivity=46.5, MassDensity=7800, SpecificHeat=.502);
That is invalid. It is converted internally into
model.MaterialProperties("ThermalConductivity", 46.5, "MassDensity", 7800, "SpecificHeat", .502);
which attempts to use the string "ThermalConductivity" as an index into the model.MaterialProperties array.
You instead need something like
model.MaterialProperties = materialProperties(ThermalConductivity=46.5, ...
MassDensity=7800, ...
SpecificHeat=0.502);
3 Kommentare
Walter Roberson
am 29 Sep. 2025
The call you had was simply invalid. The replacement code uses the properties that you were trying to specify, not different properties.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




