# MATLAB program to compute the potential in a square region by solving Laplace’s equation using the Finite Difference (FD) approximation method.using the “surf” and “contour” MATLAB commands

3 visualizaciones (últimos 30 días)
Sai Hitesh Gorantla el 6 de Jun. de 2020
Comentada: KSSV el 7 de Jun. de 2020
My Code:
clear all;
[X,Y] = meshgrid(linspace(0,1,20));
V = zeros(size(X));
[M,N] = size(V);
V(2:M-1,1) = zeros(M-2,1);
V(2:M-1,N) = 100;
V(1,2:N-1) = 40;
V(M,2:N-1) = 10;
for r = 1:10000
V(2:M-1,2:N-1) = 0.25*(V(3:M,2:N-1) + V(1:M-2,2:N-1) + V(2:M-1,2:N-1) + V(4:M-1,2:N-1));
end
surf(X,Y,V);
Getting Error:
>> contour(X,Y,V)
Unrecognized function or variable 'X'.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Sai Hitesh Gorantla el 6 de Jun. de 2020

Iniciar sesión para comentar.

### Respuestas (1)

KSSV el 7 de Jun. de 2020
Just rectifies the error you said:
clc; clear all ;
clear all;
[X,Y] = meshgrid(linspace(0,1,20));
V = zeros(size(X));
[M,N] = size(V);
V(2:M-1,1) = zeros(M-2,1);
V(2:M-1,N) = 100;
V(1,2:N-1) = 40;
V(M,2:N-1) = 10;
for r = 1:10000
V(2:M-1,2:N-1) = 0.25*(V(3:M,2:N-1) + V(1:M-2,2:N-1) ....
+ V(2:M-1,2:N-1) + V(2:M-1,2:N-1));
end
surf(X,Y,V);
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Sai Hitesh Gorantla el 7 de Jun. de 2020
KSSV el 7 de Jun. de 2020
I have already mentioned it rectifies onl the error. For expected contour, you have to check your code according to the theory or formula.

Iniciar sesión para comentar.

### Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by