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

3 ビュー (過去 30 日間)
Mustafa Birkan Kilicaslan 2021 年 12 月 18 日

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);
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 件のコメント表示非表示 6 件の古いコメント
Voss 2021 年 12 月 19 日
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.

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

### 回答 (1 件)

Meg Noah 2021 年 12 月 25 日
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);
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);

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

### カテゴリ

Find more on Fluid Dynamics in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by