Getting "Error using horzcat." when trying to draw displacement graph for a Mechanism

2 views (last 30 days)
First of, I am new to Matlab and sorry for my bad English. I'll try to explain clearly. I need to draw the displacement graph of a mechanism that has degrees of freedom = 1. That means every movement depends on the "theta21" angle. I tried to code that but I am having that error. What am i missing?
Mechanism;
My code;
A0A = 12.6; AB = 14; AD = 37.1;
EB = 45.5; BD =22.4; alfa = 39;
teta21 = linspace(128.57,488.57);
x1 = [1 -25.2*cosd(teta21-45) -1217.65];
y1 = roots(x1); A0D = y1(y1>=0);
teta31 = asind((A0D*sind(45)-A0A*sind(teta21))/AD);
epsilon = acosd((power(A0A,2)+power(AD,2)-power(A0D,2))/(2*A0A*AD));
A0B = sqrt((power(A0A,2)+power(AB,2))-(2*A0A*AB*cosd(epsilon)));
beta = acosd((A0D*cosd(45)-BD*cosd(teta31))./(A0B));
gamma = 180-(alfa+beta);
x2 = [1 (-2.*A0B.*cosd(gamma)) -1796.68];
y2 = roots(x2); A0E = y2(y2>=0);
A0Ex = A0E*cosd(alfa);
Error that i got;
  7 Comments
Voss
Voss on 19 Dec 2021
That seems reasonable. It will give you 100 teta21 angles, spanning one complete period.
The next line calculates the cosine of teta21 and prepends and appends some endpoints. Also reasonable.
But the next line after that is what I'm not sure about. Unless the call to 'roots' here refers to some function in a toolbox I don't have (or a function you wrote, for instance), 'roots' is used to find the roots of a polynomial. In this case the polynomial is of degree 101 and roots returns 101 roots. This seems to be not what is intended, since you say you get 2 roots.
You can find out what roots function gets called by doing this on the command line:
which roots -all
and see if there are any anywhere besides in the MATLAB polyfun directory.

Sign in to comment.

Answers (1)

Meg Noah
Meg Noah on 25 Dec 2021
This executes without error, but I'm unclear about whether it solves your problem.
A0A = 12.6; AB = 14; AD = 37.1;
EB = 45.5; BD =22.4; alfa = 39;
teta21 = linspace(128.57,488.57);
x1 = [1 -25.2*cosd(teta21-45) -1217.65];
y1 = roots(x1); A0D = y1(y1>=0);
teta31 = asind((A0D*sind(45)-A0A*sind(teta21))/AD);
epsilon = acosd((power(A0A,2)+power(AD,2)-power(A0D,2))/(2*A0A*AD));
A0B = sqrt((power(A0A,2)+power(AB,2))-(2*A0A*AB*cosd(epsilon)));
beta = acosd((A0D*cosd(45)-BD*cosd(teta31))./(A0B));
gamma = 180-(alfa+beta);
x2 = horzcat(complex(1,0), -2.0*A0B'*cosd(gamma), complex(-1796.68,0));
y2 = roots(x2); A0E = y2(y2>=0);
A0Ex = A0E*cosd(alfa);

Categories

Find more on Fluid Dynamics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!