I am interested in creating an actual path where I calculate a given function for a particle that travels along a given path. I am new to MATLAB, and I am having trouble creating a circular path. I can graph a circle (there are many MATLAB tutorials that show how to do this), but I would need to call such a path by one variable name, say rpath. Thus when I am prompted to enter the path the particle will take, I can enter rpath, and the particle will take a circular path starting from (1,0) and ending at (1,0) in the complex plane (I have the complex plane already programmed, I am just looking for the path. This seems a little bit more complicated than all the other circle questions I can find. My trouble is trying to create such a path in MATLAB.
For a straight line starting and ending at a specific point, I did the following, which works:
x = [0.4:0.01:1.5];
y = (-1.55/1.1).*x + (1.55*1.5/1.1);
complex = x+iy
Complex = fliplr(complex)
B_01n = Complex
Thus B_01n here is my path, and I enter this when I am asked for a path. I want to do the same for a circular path with the given conditions above. Any suggestions?

 채택된 답변

Star Strider
Star Strider 2017년 5월 30일

0 개 추천

This works:
rpath = exp(linspace(0, 2*pi)*1i);
figure(1)
plot(real(rpath), imag(rpath))
grid
axis equal
axis([-2 2 -2 2])

댓글 수: 4

BM
BM 2017년 5월 30일
편집: BM 2017년 5월 30일
Can't believe I didn't think of the exponential function! Works well, but not perfect yet.
The path should start at (1,0) and end at (1,0). I should add that I would like the path to have its lowest point at (1,0) as well. Would linspace allow me to set a certain amount of steps in my path if I wanted say 50 steps, or 100 steps?
Thank you.
This is the best I can do:
rpath = exp((linspace(0, 2*pi)-pi/2)*1i)+[1+1i];
figure(1)
plot(real(rpath), imag(rpath))
grid
axis equal
axis([-0.5 2.5 -0.5 2.5])
text(real(rpath(1)), imag(rpath(1)), sprintf('\\uparrow\n[%.1f+%.1fj]\nStart',real(rpath(1)),imag(rpath(1))), 'VerticalAlignment','top')
The third argument to linspace are the number of points you want it to calculate. The default is 100, and you can generate as many points as your computer has the memory to accommodate. I find that 100 plots a decent circle, however this depends on the size and resolution of your monitor, unless you need more or fewer points for some other reason.
BM
BM 2017년 6월 2일
Yes, modified the code, starting from what you gave me. It works beautifully. Thanks again.
Star Strider
Star Strider 2017년 6월 2일
My pleasure.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

BM
2017년 5월 30일

댓글:

2017년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by