フィルターのクリア

Axis problem in contour plotting

6 ビュー (過去 30 日間)
John Doe
John Doe 2019 年 7 月 30 日
コメント済み: Star Strider 2019 年 8 月 1 日
I have plotted this equation by this :
clear all
close all
a=1000;
b=1000;
v0=100;
V=zeros(1000);
V(:,1000)=0;
V(:,1)=0;
V(1,:)=0;
V(1000,:)=100;
[X,Y]=meshgrid(0.01:0.01:10, 0.005:0.005:5);
for x=1:1000
for y=1:1000
sum=0;
for k=1:111
n=(2*k)-1;
s=((sin(n.*pi.*x./a)).*(sinh(n.*pi.*y./a)))./(n.*sinh(n.*pi.*(b./a)));
sum=sum+s;
end
V(x,y)=(4.*v0./pi).*sum; %here
end
end
figure
[C,h]=contourf(V);
clabel(C,h)
grid on;
axis('square')
The problem is after running I get this sort of plot:
I am supposed to get something like this :
If I swap V(x,y) with V(y,x) [commented in the code], then I get the right axis. What is happening? Are my x,y values getting interchanged or something? How to resolve this issue? Kindly help!
Thanks!

採用された回答

Star Strider
Star Strider 2019 年 7 月 31 日
If you use the meshgrid outputs (with one additional argument, so one additional matrix) you get the result you want. It also avoids the loops and is likely much faster:
a=1000;
b=1000;
v0=100;
[X,Y,K]=meshgrid(1:1000, 1:1000, 1:111);
N = 2*K-1;
s = @(x,y,n) ((sin(n.*pi.*x./a)).*(sinh(n.*pi.*y./a)))./(n.*sinh(n.*pi.*(b./a)));
V = 4*v0/pi*sum(s(X,Y,N),3);
figure
[C,h]=contourf(V);
clabel(C,h)
grid on;
axis('square')
I won’t post the plot image here, because it is the one you are supposed to get, and posting it would be redundant.
  6 件のコメント
Adam Danz
Adam Danz 2019 年 8 月 1 日
編集済み: Adam Danz 2019 年 8 月 1 日
"Truly a MVP of this community"
@John Doe, I +1'd for ya ;)
Star Strider
Star Strider 2019 年 8 月 1 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by