MATLAB Answers

0

Trouble with Nested Function - So I am trying to have 'equation1' return the outputs [G, H, K, C] but it doesn't recognize them... why? Any help is appreciated

Asked by Monica Treacy on 24 Oct 2019
Latest activity Answered by Stephan
on 24 Oct 2019
function [theta3, theta4] = cr_analysis2(L1,L2,L3,L4,theta1,theta2,omega)
function [G, H, K, C] = equation1(L1,L2,L3,L4,theta1,theta2, omega)
i = theta2:360
T1S = sind(theta1);
T2S = sind(i);
T1C = cosd(theta1);
T2C = cosd(i);
G = 2 * L1 * L4 * T1C - 2 * L2 * L4 .* T2C
H = 2 * L1 * L4 * T1S - 2 * L2 * L4 .* T2S
inK = (T1C .* T2C) + (T1S .* T2S);
K = L1^2 + L2^2 - L3^2 + L4^2 - (2 * L1 * L2 .* inK)
C = omega .* sqrt(H.^2 - K.^2 + G.^2);
end
theta3 = C;
theta4 = K;

  0 Comments

Sign in to comment.

1 Answer

Stephan 님의 답변 24 Oct 2019

% Variables to play with
L1 = 1;
L2 = 3;
L3 = 4;
L4 = 2.6
theta1 = 15;
theta2 = 47.5;
omega = 66;
% Call your function
[theta3, theta4] = cr_analysis2(L1,L2,L3,L4,theta1,theta2,omega);
% Corrected function
function [theta3, theta4] = cr_analysis2(L1,L2,L3,L4,theta1,theta2,omega)
[~, ~, C, K] = equation1;
function [G, H, K, C] = equation1
i = theta2:360;
T1S = sind(theta1);
T2S = sind(i);
T1C = cosd(theta1);
T2C = cosd(i);
G = 2 * L1 * L4 * T1C - 2 * L2 * L4 .* T2C;
H = 2 * L1 * L4 * T1S - 2 * L2 * L4 .* T2S;
inK = (T1C .* T2C) + (T1S .* T2S);
K = L1^2 + L2^2 - L3^2 + L4^2 - (2 * L1 * L2 .* inK);
C = omega .* sqrt(H.^2 - K.^2 + G.^2);
end
theta3 = C;
theta4 = K;
end

  0 Comments

Sign in to comment.