# 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 vues (au cours des 30 derniers jours)
Sai Hitesh Gorantla le 6 Juin 2020
Commenté : KSSV le 7 Juin 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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Sai Hitesh Gorantla le 6 Juin 2020

Connectez-vous pour commenter.

### Réponses (1)

KSSV le 7 Juin 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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Sai Hitesh Gorantla le 7 Juin 2020
KSSV le 7 Juin 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.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Programming dans Help Center et File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by