Matrix dimensions must agree error

10 ビュー (過去 30 日間)
Alexandros Panagi
Alexandros Panagi 2018 年 12 月 13 日
編集済み: madhan ravi 2018 年 12 月 14 日
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 日
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.

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by