PINN for Laplace eq in a rectangular geometry
49 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Abhinav Aravindan
on 9 Dec 2024 at 7:14
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”:
See Also
Categories
Find more on Geometry and Mesh in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!