I have created a function to calculate an angle specified as theta4. For the inputs I am using two vector values and for an output I want to get 3 values while I am only getting 1.
function [theta4] = ThetaFour(L, theta2)
a = L(1);
b = L(2);
c = L(3);
d = L(4);
k1 = (a)/(b);
k2 = (a)/(d);
k3 = ((a^2) + (b^2) - (c^2) + (d^2))/(2*b*d);
A = (cosd(theta2)) - k1 -(k2*cosd(theta2)) + k3;
B = -2*sind(theta2);
C = k1 - ((k2 + 1)*(cosd(theta2))) + k3;
num = -B - sqrt((B.^2)-(4*A.*C));
den = 2*A;
theta4 = 2*atand(num/den);
fprintf('theta4 is %.1f\n', theta4);
end

댓글 수: 1

From the code written in function , it appears the outputs vary according to number of inputs... how do you expect more number of outputs for only one input ?
theta4 = real(ThetaFour(rand(1,4),20*rand(1))) % 1 value
theta4 = 34.3879
theta4 = real(ThetaFour(rand(1,4),20*rand(1,2))) % 2 value
theta4 = 1×2
28.1361 16.2525
theta4 = real(ThetaFour(rand(1,4),30*rand(1,3))) % 3 values
theta4 = 1×3
25.5867 23.3448 27.1002
function [theta4] = ThetaFour(L, theta2)
a = L(1);
b = L(2);
c = L(3);
d = L(4);
k1 = (a)/(b);
k2 = (a)/(d);
k3 = ((a^2) + (b^2) - (c^2) + (d^2))/(2*b*d);
A = (cosd(theta2)) - k1 -(k2*cosd(theta2)) + k3;
B = -2*sind(theta2);
C = k1 - ((k2 + 1)*(cosd(theta2))) + k3;
num = -B - sqrt((B.^2)-(4*A.*C));
den = 2*A;
theta4 = 2*atand(num./den);
% fprintf('theta4 is %.1f\n', theta4);
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2018년 2월 21일
편집: Stephen23 2018년 2월 21일

0 개 추천

theta4 = 2*atand(num./den);
^ element-wise divide

카테고리

도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2018년 2월 21일

댓글:

2023년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by