Plotting 3 variable functions (Laplace equation)

1 Ansicht (letzte 30 Tage)
John Doe
John Doe am 19 Jul. 2019
Kommentiert: doancong chinh am 2 Apr. 2020
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.

Akzeptierte Antwort

Star Strider
Star Strider am 19 Jul. 2019
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 Kommentare
Star Strider
Star Strider am 23 Jul. 2019
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 am 2 Apr. 2020
please help me to solve this exercise, thanks a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by