I am getting this warning "Matrix is singular to working precision." and my surf plot is not showing.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gabriel Mbokoma
am 12 Jun. 2024
Bearbeitet: Aquatris
am 12 Jun. 2024
I want to plot the 3D plot for the following function
, where
and
. I tried ploting with the code attached, but i am not getting a surface plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714211/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714216/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714221/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 12 Jun. 2024
You need to do element-wise opeerations in your ‘u’ function, so:
u = @(x,y)(-4*pi*exp(-5*pi*pi*0.5).*cos(2*pi*x).*sin(pi*y))./(2 + exp(-5*pi*pi*0.5).*sin(2*pi*x).*sin(pi*y));
instead of:
u = @(x,y)(-4*pi*exp(-5*pi*pi*0.5)*cos(2*pi*x)*sin(pi*y))/(2 + exp(-5*pi*pi*0.5)*sin(2*pi*x)*sin(pi*y));
With that change, it works —
exact_u
function exact_u
%u = @(x,y)(-4*0.01*pi*exp(-5*pi*pi*(0.01)*0.5)*cos(2*pi*x)*sin(pi*y))/(2 + exp(-5*pi*pi*(0.01)*0.5)*sin(2*pi*x)*sin(pi*y));
u = @(x,y)(-4*pi*exp(-5*pi*pi*0.5).*cos(2*pi*x).*sin(pi*y))./(2 + exp(-5*pi*pi*0.5).*sin(2*pi*x).*sin(pi*y));
[X,Y]=meshgrid(0:0.1:1);
Z = u(X,Y);
figure
surf(X,Y,Z);
title('U(x,y)');
xlabel('x');
ylabel('y');
zlabel('u');
grid on
box on
%Interpolation
[X1,Y1] = meshgrid(0:0.05:1);
Z1 = interp2(X,Y,Z,X1,Y1);
figure
surf(X1,Y1,Z1)
title('U(x,y)');
xlabel('x');
ylabel('y');
zlabel('u');
grid on
box on
end
.
0 Kommentare
Weitere Antworten (1)
Aquatris
am 12 Jun. 2024
Bearbeitet: Aquatris
am 12 Jun. 2024
You are doing a matrix mutiplication when you call the u() function, since you call u function with matrix arguments X and Y. Then something happens (!) and your whole matrix because NaN
I think you did not mean to do a matrix multiplication in the u = @(x,y) function. So change it to element wise multiplication and division and it seems to work.
exact_u
function exact_u
%u = @(x,y)(-4*0.01*pi*exp(-5*pi*pi*(0.01)*0.5)*cos(2*pi*x)*sin(pi*y))/(2 + exp(-5*pi*pi*(0.01)*0.5)*sin(2*pi*x)*sin(pi*y));
u = @(x,y)(-4*pi*exp(-5*pi*pi*0.5).*cos(2*pi*x).*sin(pi*y))./(2 + exp(-5*pi*pi*0.5).*sin(2*pi*x).*sin(pi*y));
[X,Y]=meshgrid(0:0.1:1);
Z = u(X,Y);
figure
surf(X,Y,Z);
title('U(x,y)');
xlabel('x');
ylabel('y');
zlabel('u');
grid on
box on
%Interpolation
[X1,Y1] = meshgrid(0:0.05:1);
Z1 = interp2(X,Y,Z,X1,Y1);
figure
surf(X1,Y1,Z1)
title('U(x,y)');
xlabel('x');
ylabel('y');
zlabel('u');
grid on
box on
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!