Plotting 3 variable functions (Laplace equation)
2 ビュー (過去 30 日間)
古いコメントを表示
CONTOUR PLOTTING OF LAPLACE EQUATION

I wish to plot this equation. The gist that I get is :
- I have to vary x,y and n
- n will have odd numbers only for this arrangement
Accordingly I have typed this out in MATLAB:
clc
clear all
close all
v0=100;
a=5;
b=10;
x=1:1:200;
y=1:1:200;
[x,y]=meshgrid(x,y);
for n=1:2:100
z(n)=(4.*v0./pi).*(sin(n.*pi.*x./a).*(sinh(n.*pi.*y./a)./(n.*sinh(n.*pi.*b./a))));
end
contour3(x,y,z);
From my basic understanding of plotting, I have to index z so that I can keep the values for plotting later. But an error is generated at the z(n) line.The error says,
Subscripted assignment dimension mismatch.
I know this is a matrix size problem, but I am unable to find a feasible solution. How do I solve this size problem? Is there any better way to formulate this equation since it is a 3-variable formula? Or is there any constraint of choosing the range of x,y? If you have a clear explanation and a solution for this, kindly help.
Thanks.
0 件のコメント
採用された回答
Star Strider
2019 年 7 月 19 日
You need to create matrices from ‘x’ and ‘y’ using either meshgrid or ndgrid. Then, you can plot the contours.
Please re-examine your values for ‘x’ and ‘y’. I divided them by 100 here to get what I consider to be a reasonably acceptable plot:
v0=100;
a=5;
b=10;
x=1:1:200;
y=1:1:200;
n=1:2:100;
[X,Y,N]=meshgrid(x/100,y/100,n);
Z = @(x,y,n) (4.*v0./pi).*(sin(n.*pi.*x./a).*(sinh(n.*pi.*y./a)./(n.*sinh(n.*pi.*b./a))));
Zs = sum(Z(X,Y,N),3); % Sum Over ‘n’
figure
contourf(x/100, y/100, Zs)
axis('equal')
Experiment to get the results you want.
7 件のコメント
Star Strider
2019 年 7 月 23 日
In order to make them agree, one way is to transpose ‘Zs2’:
Z = (1/4)*(Zs1+Zs2');
That works, and it’s compatible with the contourf call (although the resulting plot looks strange).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!