Matrix dimensions must agree error
10 views (last 30 days)
Show older comments
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 Comment
madhan ravi
on 14 Dec 2018
Edited: madhan ravi
on 14 Dec 2018
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.
Answers (1)
Guillaume
on 13 Dec 2018
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 Comment
Image Analyst
on 14 Dec 2018
And what are "the intercept coordinates"? What is intercepting what?
A diagram would help.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!