Matrix dimensions must agree error

Im trying to make a simple function in which you input the radius, centre of a circle and the intercept coordinates to output a plot with the circle, radius and tangent showing but I seem to be stuck here any help is appreciated
function circle2
x0=input('centre x-axis');
y0=input('centre y-axis');
r=input('radius');
xp=input('P x-coord');
yp=input('P y-coord');
%Parameters
th=0:0.01:2.*pi;
%Value for x
x=r.*cos(th)+x0;
%Value for y
y=r.*sin(th)+y0;
%Differentiation
dxdth = -r.*sin(th);
dydth = r.*cos(th);
%Gradient
dydx = dydth./dxdth;
%Calculate intercept
intcpt = yp - dydx.*xp;
%x vector for tangent
xt= linspace(xp-1,xp+1,2);
%Calculate tangent
yt = dydx.*xt+intcpt;
if yp~=yt
xt=xp-2<=xt<=xp+2
yt=dydx(xt-xp)+yp
elseif yp==y0
xt=xp
yt=yp-5<=yt<=yp+5
end
%Plot intercept
plot(x,y);
hold on
plot(xp, yp);
%Plot tangent
plot(xt, yt);
%Plot radius
plot ([x0 xp],[y0 yp])
%Axis limit values
axis ([-1.25*r 1.25*r -1.25*r 1.25*r]);

댓글 수: 1

madhan ravi
madhan ravi 2018년 12월 14일
편집: madhan ravi 2018년 12월 14일
It's truly impolite to close a question (and to curse with vulgar words as you flagged my answer which is why I deleted my answer) after someone has made an effort to answer your question.

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

답변 (1개)

Guillaume
Guillaume 2018년 12월 13일

0 개 추천

What are these lines supposed to do?
xt=xp-2<=xt<=xp+2
yt=yp-5<=yt<=yp+5
Whatever you meant for these, I'm fairly certain it's not doing it. a <= b is always going to result in an array of true or false (0 or 1). So you're comparing an array of 0 and 1 with xp + 2.
Typically, when novices write this sort of expressions they mean:
xt = xp-2 <= xt & xt <= xp+2
yt = yp-5 <= yt & yt <= yp+5
but here even that would make no sense.

댓글 수: 1

Image Analyst
Image Analyst 2018년 12월 14일
And what are "the intercept coordinates"? What is intercepting what?
A diagram would help.

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

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2018년 12월 13일

편집:

2018년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by