Plotting a function with difference between 2 vectors?

조회 수: 3 (최근 30일)
Niklas Kurz
Niklas Kurz 2021년 5월 8일
편집: Niklas Kurz 2021년 5월 9일
I want to plot where is the magnitude of the distance between 2 vectors: :
If I would implement this idea in Matlab:
[r1,r2] = meshgrid(linspace(-1,1,100));
phi = 1./(r1-r2);
mesh(r1,r2,phi)
what's nor really any kind of potential. Instead
[r1,r2] = meshgrid(linspace(-1,1,100));
phi = 1./sqrt((r1.^2+r2.^2));
mesh(r1,r2,phi)
is drawing the shape I sougth. Where does this difference originate from?

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 5월 8일
편집: Cris LaPierre 2021년 5월 8일
The shape is caused by where you can divide by 0. The difference is that, in the first case, this occurs along the diagonal line r1-r2=0. In the second case, the only time you divide by 0 is when r1=r2=0, hence the peak at a single point, (0,0).
  댓글 수: 1
Niklas Kurz
Niklas Kurz 2021년 5월 9일
편집: Niklas Kurz 2021년 5월 9일
yea, I guess u have to think about meshgrid(r1,r2) as a "vectorspace" spaned by the unit vecots r1 and r2 and not as indivdual vectors like I did.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by