Matrix dimensions must agree error

10 visualizaciones (últimos 30 días)
Alexandros Panagi
Alexandros Panagi el 13 de Dic. de 2018
Editada: madhan ravi el 14 de Dic. de 2018
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 comentario
madhan ravi
madhan ravi el 14 de Dic. de 2018
Editada: madhan ravi el 14 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 13 de Dic. de 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 comentario
Image Analyst
Image Analyst el 14 de Dic. de 2018
And what are "the intercept coordinates"? What is intercepting what?
A diagram would help.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by