How to solve 2D Laplace Equation using finite difference method (GUI)

Dear all,
I have problems to solve laplace equation 2d where users can define their own boundaries by drawing up a two-dimensional then matlab should be able to give a solution of laplace equation with a boundary that made earlier and must be able to calculate how many percent about the error that made.
I've made a script but still not right, maybe you can help me .. thank you.
this is my script :
axis([2 20 2 20])
hold on
grid on
xy = [];
n = 0;
but = 1;
while but == 1;
[xi,yi,but] = ginput(1);
plot(xi,yi,'ro')
n = n+1;
xy(:,n) = [xi;yi];
end
% Plot grafik.
x = round(xy(1,:));
y = round(xy(2,:));
T=zeros(max(x),max(y));
for w=min(x):max(x)-1,
for q=min(y):max(y)-1,
T(w,q+1) = w,q+1;
T(w,q-1) = w,q-1;
T(w+1,q) = w+1,q;
T(w-1,q) = w-1,q;
T(w,q) = (T(w,q+1)+T(w,q-1)+T(w+1,q)+T(w-1,q))/4
end
end
contourf(T,'DisplayName','T');figure(gcf);
plot(x,y,'b-');
hold off;

1 commentaire

try with this script:
n=11; % nodes
l=1.0; % lenght
w=.5; % width
x=linspace(0,l,n);
y=linspace(0,w,n);
T=zeros(n);
% Boundary conditions:
T(n,1:n)=273.0 % Top
T(1,1:n)=273.0 % Bottom
T(1:n,1)=573.0 % left
T(1:n,n)=273.0 % right
eps=1e-6;
error=1;
k=0;
while error>eps
k=k+1
Told=T
for i=2:n-1;
for j=2:n-1;
T(i,j)=.25*(T(i+1,j)+T(i-1,j)+T(i,j-1)+T(i,j+1));
end
end
error=max(max(abs(Told-T)));
end
subplot(2,1,1),contour(x,y,T),colormap,
title('Temperature(steady-state)'),xlabel('x'),ylabel('y'),colorbar;
subplot(2,1,2),pcolor(x,y,T),shading interp,colormap,
title('Temperature(steady-state)'),xlabel('x'),ylabel('y'),colorbar;

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Stochastic Differential Equation (SDE) Models dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by