PINN for Laplace eq in a rectangular geometry

조회 수: 16 (최근 30일)
sepideh
sepideh 2024년 12월 4일
편집: sepideh 2024년 12월 9일
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

답변 (1개)

Abhinav Aravindan
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”:
  댓글 수: 1
sepideh
sepideh 2024년 12월 9일
편집: sepideh 2024년 12월 9일
Thank you very much.
I did not change the code,
I put it here as is in the link I attached
in the website , they wrote like this. when I run the original code (with size in the for loop) it works.
but when I use the same structure and I only change the geometry and equation, MATLAB gives me an error based on this "size" in the for loop.
So I was wondering what does it represent in the code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by