Need Help to find the error

6 ビュー (過去 30 日間)
Alex
Alex 2012 年 10 月 21 日
Hello, I need from an array consisting of 10,000 items and are the coordinates (X and Y) of the ellipse to determine the minimum and maximum distance between two points. The problem is that the origin of 10000 should have 9999 range, the mine, the program calculates only 9998. you can verify using the command size(dist).
clear all
clc
A=[2/3 -2/3; 2/3 7/3];
[eigenvektor, eigenvalue]=eig(A);
n = 10000;
theta = linspace(0,2*pi,n);
r = 1;
x =r.*cos(theta);
y =r.*sin(theta);
plot(x,y,'.')
v = [x;y];
w=A*v;
xcoor=w(1,:);
ycoor=w(2,:);
i=0;
while i<n
i=i+1;
dxx2=xcoor(n-i:length(xcoor)-i);
dxx1=xcoor(n-(i+1):length(xcoor)-(i+1));
dyy2=xcoor(n-i:length(ycoor)-i);
dyy1=xcoor(n-(i+1):length(ycoor)-(i+1));
dist(i)=sqrt( (dxx2-dxx1)^2 + (dyy2-dyy1)^2);
end
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 21 日
which distance do you want, maybe there is a better way to do it
Alex
Alex 2012 年 10 月 21 日
distance between two points of the ellipse. The circumference of an ellipse has 10 000 points. maxdistance=max(dist) maxdistance =0.0008378
mindistance=min(dist) mindistance = 6.581D-08 The formula for the distance set me right. The problem is that in its cycle, I do not get to a end of the array.

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 21 日
編集済み: Azzi Abdelmalek 2012 年 10 月 21 日
r = 1;
x =r.*cos(theta);
y =r.*sin(theta);
plot(x,y,'.')
v = [x;y];
w=A*v;
xcoor=w(1,:);
ycoor=w(2,:);
figure,plot(xcoor,ycoor)
dist=sqrt(xcoor.^2+ycoor.^2)*2
min(dist)
max(dist)
If the origin of your ellipse is not (0,0) we can make translation
Also you don't need 10000 points, 5000 points are enough
dist=sqrt(xcoor(1:5000).^2+ycoor(1:5000).^2)
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 21 日
編集済み: Azzi Abdelmalek 2012 年 10 月 21 日
do you want the distance between two consecutive points?
then look at Star's answer
Alex
Alex 2012 年 10 月 21 日
thank you very much:)

サインインしてコメントする。

その他の回答 (1 件)

Star Strider
Star Strider 2012 年 10 月 21 日
Instead of your while loop, I suggest:
dxx = diff(xcoor);
dyy = diff(ycoor);
dist = hypot( dxx, dyy);
Does this do what you want?

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by