why do i get the error using alpha too many output arguments, can anyoen help please.

2 ビュー (過去 30 日間)
jack
jack 2023 年 2 月 22 日
編集済み: Les Beckham 2023 年 2 月 22 日
% Define the given parameters
OA = 0.45; % m
AAp = 0.15; % m
OB = 0.70; % m
BC = 0.65; % m
CD = 0.45; % m
DE = 0.55; % m
d = 0.30; % m
p = 1; % m
t = sqrt(p^2 - d^2); % m
% Define the crank angle range and step
phi_min = 0;
phi_max = 2*pi;
d_phi = 0.001;
% Initialize arrays to store the crank angle and E position
phi_array = phi_min:d_phi:phi_max;
y_E_array = zeros(size(phi_array));
% Calculate the position of point E for each crank angle
for i = 1:length(phi_array)
phi = phi_array(i);
theta = asin(OB*sin(phi)/BC); % Solve for theta using sin law
% Calculate the positions of points C and E
OC = BC*cos(theta);
CE = DE*cos(alpha);
angle_TCE = atan((d - CE)/(t + OC));
angle_ECT = atan(CE/(d - t - OC));
y_E = (d - CE)*tan(angle_TCE) + CE*tan(angle_ECT);
% Store the E position in the array
y_E_array(i) = y_E;
end
Error using alpha
Too many output arguments.
% Plot the position of point E as a function of the crank angle
plot(phi_array, y_E_array);
xlabel('Crank angle (rad)');
ylabel('Position of E (m)');

回答 (3 件)

Askic V
Askic V 2023 年 2 月 22 日
編集済み: Askic V 2023 年 2 月 22 日
You didn't define variable alpha. Because of that, Matlab thinks you want to use built in functionality:
help alpha
alpha - Get or set alpha properties for objects in the current Axis

Kevin Holly
Kevin Holly 2023 年 2 月 22 日
alpha is a function used in plotting to change transparency. Below I change alpha to Alpha and defined it as a variable equal to 30.
% Define the given parameters
OA = 0.45; % m
AAp = 0.15; % m
OB = 0.70; % m
BC = 0.65; % m
CD = 0.45; % m
DE = 0.55; % m
d = 0.30; % m
p = 1; % m
t = sqrt(p^2 - d^2); % m
Alpha = 30;
% Define the crank angle range and step
phi_min = 0;
phi_max = 2*pi;
d_phi = 0.001;
% Initialize arrays to store the crank angle and E position
phi_array = phi_min:d_phi:phi_max;
y_E_array = zeros(size(phi_array));
% Calculate the position of point E for each crank angle
for i = 1:length(phi_array)
phi = phi_array(i);
theta = asin(OB*sin(phi)/BC); % Solve for theta using sin law
% Calculate the positions of points C and E
OC = BC*cos(theta);
CE = DE*cos(Alpha);
angle_TCE = atan((d - CE)/(t + OC));
angle_ECT = atan(CE/(d - t - OC));
y_E = (d - CE)*tan(angle_TCE) + CE*tan(angle_ECT);
% Store the E position in the array
y_E_array(i) = y_E;
end
% Plot the position of point E as a function of the crank angle
plot(phi_array, y_E_array);
Warning: Imaginary parts of complex X and/or Y arguments ignored.
xlabel('Crank angle (rad)');
ylabel('Position of E (m)');

Les Beckham
Les Beckham 2023 年 2 月 22 日
編集済み: Les Beckham 2023 年 2 月 22 日
You get this error because you haven't defined alpha before Matlab tries to execute this line of code
CE = DE*cos(alpha);
Since Mathworks made the extremely poor choice of naming one of it's graphics functions alpha, Matlab tries to execute that function to evaluate the argument to the cos function. But, the alpha function doesn't have any output arguments, so you get the error.
I think you probably meant to use phi here.
% Define the given parameters
OA = 0.45; % m
AAp = 0.15; % m
OB = 0.70; % m
BC = 0.65; % m
CD = 0.45; % m
DE = 0.55; % m
d = 0.30; % m
p = 1; % m
t = sqrt(p^2 - d^2); % m
% Define the crank angle range and step
phi_min = 0;
phi_max = 2*pi;
d_phi = 0.001;
% Initialize arrays to store the crank angle and E position
phi_array = phi_min:d_phi:phi_max;
y_E_array = zeros(size(phi_array));
% Calculate the position of point E for each crank angle
for i = 1:length(phi_array)
phi = phi_array(i);
theta = asin(OB*sin(phi)/BC); % Solve for theta using sin law
% Calculate the positions of points C and E
OC = BC*cos(theta);
CE = DE*cos(phi); %<<<<< changed alpha to phi here
angle_TCE = atan((d - CE)/(t + OC));
angle_ECT = atan(CE/(d - t - OC));
y_E = (d - CE)*tan(angle_TCE) + CE*tan(angle_ECT);
% Store the E position in the array
y_E_array(i) = y_E;
end
% Plot the position of point E as a function of the crank angle
plot(phi_array, y_E_array);
Warning: Imaginary parts of complex X and/or Y arguments ignored.
xlabel('Crank angle (rad)');
ylabel('Position of E (m)');
grid on

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by