MATLAB homework help

2 ビュー (過去 30 日間)
Ben Stewart
Ben Stewart 2011 年 11 月 1 日
I've been asked to write a program that determines the center and radius of a circle that passes through three given points. The program should ask the user to enter the coordinates of the point one at a time. The program displays the coordinate of the center and the radius, and makes a plot of the circle and the three points displayed on the plot with asterisk markers.
I know how to do this algebraically with the distance formula yielding three equations and three unknowns but I'm new to using MATLAB (programming in general for that matter) and I'm having trouble translating that into a program using MATLAB.
Another way to do it is using the code below
x1=input('First x coordinate');
x2=input('Second x coordinate');
x3=input('Third x coordinate');
y1=input('First y coordinate');
y2=input('Second y coordinate');
y3=input('Third y coordinate');
t1 = x3^2-x2^2+y3^2-y2^2;
t2 = x1^2-x3^2+y1^2-y3^2;
t3 = x2^2-x1^2+y2^2-y1^2;
d = x1*y2-x2*y1+x2*y3-x3*y2+x3*y1-x1*y3
a = 1/2*(t1*y1+t2*y2+t3*y3)/d
b = -1/2*(t1*x1+t2*x2+t3*x3)/d
d is the radius, and the center of the circle is (a,b) but then plotting the circle is what I'm having trouble with.
I would really appreciate assistance Thanks!

回答 (1 件)

Daniel Shub
Daniel Shub 2011 年 11 月 1 日
This will plot a circle with radius 1 and center (0,0). Can you see where to add a and b to get a circle centered on (a,b)? How about scaling it to get diameter d?
x = -1:0.01:1;
plot([x, fliplr(x)], [sqrt(1-x.^2), -sqrt(1-fliplr(x).^2)]);
axis square;

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by