필터 지우기
필터 지우기

Plotting 3 variable functions (Laplace equation)

조회 수: 4 (최근 30일)
John Doe
John Doe 2019년 7월 19일
댓글: doancong chinh 2020년 4월 2일
CONTOUR PLOTTING OF LAPLACE EQUATION
Capture.JPG
I wish to plot this equation. The gist that I get is :
  1. I have to vary x,y and n
  2. 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.

채택된 답변

Star Strider
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
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).
doancong chinh
doancong chinh 2020년 4월 2일
please help me to solve this exercise, thanks a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by