Modify matrix for partial plot

How can I modify the for loops to create a bracket-shaped domain? In otherwords, I would like to plot everything and omit the first quadrant. Thank you!
clear; close all; clc
n = 40;
x = linspace(0,8,n); dx = x(2)-x(1); y = x; dy = dx;
U = zeros(n);
U(n,1:n/2) =10;
U(n/2,n/2:n-1) =0;
U(1,1:n-1) = 10;
U(2:n,n/2) = 0;
U(1:n/2,n) = 7;
U(n/2:n,n/2) = 0;
alpha=1;
ddt = 1/(4*(1/dx^2+1/dy^2));
for w=1:1000
V = U;
for i = 2:n/2-1
for j = 2:n-1
U(i,j) =ddt*((V(i+1,j)-2*V(i,j)+V(i-1,j))/dx^2+ (V(i,j+1)-V(i,j)+V(i,j-1))/dy^2)+ V(i,j);
end
end
end
figure(1)
contour(y,x,U)
figure(2)
surf(y,x,U)

5 件のコメント

darova
darova 2020 年 5 月 9 日
Calculate two regions separately
Walter Roberson
Walter Roberson 2020 年 5 月 9 日
Uc = U;
Uc(1:end/2, 1:end/2) = nan;
figure(1);
contour(y, x, Uc);
figure(2)
surf(y, x, Uc, 'edgecolor', 'none')
jojo
jojo 2020 年 5 月 9 日
編集済み: jojo 2020 年 5 月 9 日
I need to do this on the calculation part please. Not the plotting part. I tried doing 2 seperate for loop but I am unable to get blank region. Is this even possible to do without 'none' ?
Walter Roberson
Walter Roberson 2020 年 5 月 9 日
surf(y, x, Uc)
The 'edgecolor', 'none' just controls drawing the edges of each face. When you have many faces, the edges start to take over the visual impression, because the edges are constant width even when the faces get small.
Walter Roberson
Walter Roberson 2020 年 5 月 9 日
x and y are both increasing, and you are using x for rows and y for columns. Which is the "first quadrant" ?
(x=0,y=0) (x=0,y=4) (x=0,y=8)
A B
(x=4,y=0) (x=4,y=4) (x=4,y=8)
C D
(x=8,y=0) (x=8,y=4) (x=8,y=8)

サインインしてコメントする。

 採用された回答

darova
darova 2020 年 5 月 9 日
編集済み: darova 2020 年 5 月 9 日

0 投票

Here are your bourndary conditions
n = 40;
x = linspace(0,8,n); dx = x(2)-x(1); y = x; dy = dx;
U = zeros(n);
U(n,1:n/2) =10;
U(n/2,n/2:n-1) =0+10;
U(1,1:n-1) = 10;
U(2:n,n/2) = 0+10;
U(1:n/2,n) = 7+3;
U(n/2:n,n/2) = 0+10;
alpha=1;
ddt = 1/(4*(1/dx^2+1/dy^2));
h = imagesc(U);
view(2)
Something is missing
I made some changes to your script. It still doesn't work

2 件のコメント

jojo
jojo 2020 年 5 月 9 日
Thanks for the effort. I'm just trying to blank out a section of the plot using for loops (actual computation) instead of plotting using 'none'
darova
darova 2020 年 5 月 9 日
I did everything i can

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 5 月 9 日

コメント済み:

2020 年 5 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by