Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
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;

Respuestas (1)

Stephan
Stephan el 24 de Oct. de 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

Community Treasure Hunt

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

Start Hunting!

Translated by