PINN for Laplace eq in a rectangular geometry
3 次查看(过去 30 天)
显示 更早的评论
Hello Dear Community
I am trying to re-write and change this code https://it.mathworks.com/help/pde/ug/solve-poisson-equation-on-unit-disk-using-pinn.html for solving the Laplace equation in a rectangular geometry.
Everything is ok up to the "Model loss function" section where I got an error about the "size" which stating that : "Not enough input arguments"
I really do not understand what this "size" in the "for loop" refers to in this code to change it in a way that code will work correctly:
function [loss,gradients] = modelLoss(model,net,XY,pdeCoeffs)
dim = 2;
[U,~] = forward(net,XY);
% Compute gradients of U and Laplacian of U.
gradU = dlgradient(sum(U,
"all" ),XY,EnableHigherDerivatives=true);
Laplacian = 0;
for i=1:size
gradU2 = dlgradient(sum(pdeCoeffs.c.*gradU(i,:),
"all" ), ...
XY,EnableHigherDerivatives=true);
Laplacian = gradU2(i,:)+Laplacian;
end
0 个评论
回答(1 个)
Abhinav Aravindan
2024-12-9
In the "Model Loss Function" for computing gradients and the Laplacian of "U" in "Solve Poisson Equation on Unit Disk Using Physics-Informed Neural Networks" example, the "for" loop is as follows:
for i=1:dim
gradU2 = dlgradient(sum(pdeCoeffs.c.*gradU(i,:),"all"), ...
XY,EnableHigherDerivatives=true);
Laplacian = gradU2(i,:)+Laplacian;
end
It appears that "dim" has been replaced with "size" in your code. The "size" function in MATLAB is used to determine the dimensions of an array and requires input arguments. Since, there are no input arguments give to “size”, this results in an error. You may refer to the below documentation for more detail:
I assume you intended to use "size" as a variable name. However, it is not recommended to use the names of MATLAB functions as variable names, as this can lead to "overshadowing".
Please refer to the below links for more information on “overshadowing”:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Conditions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!