How can I plot this solution to Laplace's equation?

I have this solution to Laplace's equation with specific boundary conditions (not necessary for question)
I am trying to plot this in 3D with the code:
x=0:.01:3;
y=0:.01:2;
[X, Y]=meshgrid(x, y);
uxy=zeros(size(X));
for n=1:20
cn=(8*sin(n*pi/2))/(n^2*pi^2*sinh(3*n*pi/2));
uxy=uxy+cn*sinh(n*pi*x/2).*sin(n*pi*y/2);
end
surf(X, Y, uxy)
It keeps telling me that my inner matrix dimensions must agree yet I cannot figure out how to fix this. If you could help me plot this, that would be great. Thanks!

 Réponse acceptée

This error occurs when two matrices being multiplied does not have consistent dimensions. In your case you put variables x and y, when you actually need to write X and Y. Try this
uxy=uxy+cn*sinh(n*pi*X/2).*sin(n*pi*Y/2);

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Produits

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by