Plotting 3 variable functions (Laplace equation)
1 次查看(过去 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!