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

9 visualizzazioni (ultimi 30 giorni)
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'.

Risposte (1)

KSSV
KSSV il 7 Giu 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 Commenti
KSSV
KSSV il 7 Giu 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.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by