Vector input, 1 output
Show older comments
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 Comment
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 = real(ThetaFour(rand(1,4),20*rand(1,2))) % 2 value
theta4 = real(ThetaFour(rand(1,4),30*rand(1,3))) % 3 values
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
Answers (1)
theta4 = 2*atand(num./den);
^ element-wise divide
Categories
Find more on Operators and Elementary Operations 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!