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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 21 Feb. 2018
Bearbeitet: Stephen23 am 21 Feb. 2018

0 Stimmen

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

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Feb. 2018

Kommentiert:

am 26 Jul. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by