Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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 回表示 (過去 30 日間)
Monica Treacy
Monica Treacy 2019 年 10 月 24 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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;

回答 (1 件)

Stephan
Stephan 2019 年 10 月 24 日
% 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