Matlab error, "Not enough input arguments" & "unrecognized function 'x'"

1 回表示 (過去 30 日間)
Mohammad Nazmus Saquib
Mohammad Nazmus Saquib 2022 年 3 月 1 日
編集済み: KSSV 2022 年 3 月 1 日
I was trying to run a script and everytime getting returned with these to errors. I can see the input arguments in workspace and still it says Not enough input arguments.
I'm attaching the code here:
clear; clc; close all; digits(6)
AISI = 10200; % select material
Tf = 70; % (F) - operating temperature
Rf = 0.5; % reliability
r_gear = 5; % gear radius (inches)
phi = 20; % pressure angle (degrees)
%vb_ratio = 5; % V-belt ratio
a = 0.5; p = 4; b = 4.75; c = 5.5; q = 6.5; r = 7.5; s = 9; t = 9.5; % distance (inches)
E = 30*10^6; % Young's modulus (lbf/inch) g = 386.1; % gravity constant (inch/s^2)
g = 386.1; % gravity constant (inch/s^2)
gamma = 0.282; % weight density of shaft material (lbf/inch^3)
x_crit = a; % the x-coordinate of the critical location (inches)
c_type = 'design'; % calculation type: 'design' or 'analysis'
d_type = 'shoulder'; % discontinuity type: 'shoulder' or 'keyway'
Torque_min = -175; Torque_max = 553;
n_d = 3.0; % design factor
if strcmp(c_type,'analysis')
ds = 1; % specify the diameter of the smaller section at the shoulder (or the diameter at the keyway)
else
ds = rand;
end
% Calculations %%%%%%%%%%%%%%%%%%%
x = linspace(0,t,500);
T_m = (Torque_max+Torque_min)/2; % torque midrange value (lbf*inch)
T_a = abs(Torque_max-Torque_min)/2; % torque midrange value (lbf*inch)
if x_crit < b , T_m = 0; T_a = 0; end
[BM_min,~,~] = bending_moment(x,Torque_min,r_gear,phi,b,t);
pp_min = pchip(x, BM_min);
BM_crit_min = ppval(pp_min, x_crit);
[BM_max, Loads, Reactions] = bending_moment(x,Torque_max,r_gear,phi,b,t);
pp_max = pchip(x, BM_max); BM_crit_max = ppval(pp_max, x_crit);
BM_mid = (BM_max + BM_min)/2; BM_amp = abs(BM_max-BM_min)/2;
area(x,BM_mid+BM_amp); grid on; xlabel('x (in)','FontSize',15); ylabel('M_{peak} (lbf*in)','FontSize',15)
M_a = abs(BM_max-BM_min)/2; % bending moment amplitude at critical location (lbf*inch)
M_m = (BM_max+BM_min)/2; % bending moment midrange at critical location (lbf*inch)
if strcmp(d_type,'keyway')
input = [ds,1,1/48,0,n_d]; % standard end-milled keyway
elseif strcmp(d_type,'shoulder')
flr = 1/16; % fillet radius (inches)
d_r = 0; % diameter ratio
dl = 0.75; % diameter of the larger section at the shoulder - use dl > 0 to override d_r value
if strcmp(c_type,'design') && ds>dl, ds = 0.9*dl; end % check if ds > dl
input = [ds,d_r,flr,dl,n_d];
end
if (~isempty(Reactions))
str = 'Reaction at right bearing center'; fprintf('\n'); fprintf('%s: (%#.4g, %#.4g) lbf \n',str,Reactions(1,1),Reactions(1,2))
str = 'Reaction at left bearing center'; fprintf('\n'); fprintf('%s: (%#.4g, %#.4g) lbf \n\n',str,Reactions(2,1),Reactions(2,2))
end
Shaft_strength_calculation(AISI,Tf,Rf,M_a,M_m,T_a,T_m,c_type,d_type,input);
% calculate the shaft deflection and slope at the critical locations
x_force = b; % the x-coordinate of the effective center of each force (inches)
x_reaction = [0; t]; % the x-coordinate of the effective center of each reaction (inches)
x_step = [a;p;c;q;r;s]; % the x-coordinate of each step point (inches)
d0 = 0.562; d1 = 1; d2 = 1.197; d3 = 1; d4 = 1; d5 = 1; d6 = 1.546 % diameter of each shaft segment (inches)
d = [d6;d5;d0;d1;d2;d3;d4];
Shaft_deflection_calculation(E,Loads,x_force,x_reaction,x_step,d)
% calculate the first critical speed of the shaft
x_gravity = [p+0.5; q+0.5]; % the x-coordinate of the center of gravity (inches)
x_o = t; % inches - the x-coordianate of the end of the overhang (inches)
intv = 10; % number of discrete intervals for each shaft segment
Weights = [10; 3]; % shaft attachment weights (lbf)
Shaft_critical_speed_calculation(E,g,gamma,Weights,x_gravity,x_reaction,x_step,x_o,d,intv)
function [BM, Loads, Reactions] = bending_moment(x,Torque,rg,rs,vbr,phi,p,b,q)
syms Flb_y Flb_z Frb_y Frb_z
Fg_t = Torque/rg; % tangential component of gear force (lbf)
Fg_r = abs(Fg_t*tand(phi)); % radial component of gear force (lbf)
Fv_net = Torque/rs; % net tension on V-belt (lbf)
Fv_bending = ((vbr+1)/(vbr-1))*Fv_net; % bending force of V-belt (lbf)
Fv_t = (Fv_net+Fv_bending)/2; % force on tight side of V-belt (lbf)
Fv_s = Fv_t/vbr; % force on slack side of V-belt (lbf)
R_g = [p+0.5,0,-rg]; % position vector of gear force (inches)
R_rb = [b+1,0,0]; % position vector of right bearing center (inches)
R_vt = [q+0.5,rs,0]; % position vector of force on tight side of V-belt (inches)
R_vs = [q+0.5,-rs,0]; % position vector of force on slack side of V-belt (inches)
M = round(vpa(cross(R_g,[0,-Fg_t,Fg_r]) + cross(R_rb,[0,Frb_y,Frb_z]) + cross(R_vt,[0,0,Fv_t]) + cross(R_vs,[0,0,Fv_s]))); % equilibrium of moments
[Frb_y, Frb_z] = solve(M,[Frb_y, Frb_z]); % calculate the reaction at the right bearing (lbf)
F = [0,Flb_y,Flb_z] + [0,-Fg_t,Fg_r] + [0,Frb_y,Frb_z] + [0,0,Fv_t] + [0,0,Fv_s]; % equilibrium of forces
[Flb_y, Flb_z] = solve(F,[Flb_y, Flb_z]); % calculate the reaction at the left bearing (lbf)
Reactions = double([Flb_y,Flb_z; Frb_y,Frb_z]);
Loads = double([Flb_y, Flb_z; -Fg_t, Fg_r; Frb_y, Frb_z; Fv_t, Fv_s]);
Mxy = @(x) Flb_y*max(x,0) - Fg_t*max(x-p-0.5,0) + Frb_y*max(x-b-1,0);
Mxz = @(x) Flb_z*max(x,0) + Fg_r*max(x-p-0.5,0) + Frb_z*max(x-b-1,0) + Fv_bending*max(x-q-0.5,0);
BMxy = double(Mxy(x)); % calculate the bending moment distribution in the xy plane
BMxz = double(Mxz(x)); % calculate the bending moment distribution in the xz plane
BM = sqrt(BMxy.^2 + BMxz.^2); % calculate the total bending moment distribution
end
The lines marked in bold are the lines which are troublesome.
  2 件のコメント
Stephen23
Stephen23 2022 年 3 月 1 日
編集済み: Stephen23 2022 年 3 月 1 日
"I can see the input arguments in workspace and still it says Not enough input arguments."
What is important is that you call the function with the required input arguments. Lets check them:
The function BENDING_MOMENT has nine input arguments, this is how you defined it:
function [BM, Loads, Reactions] = bending_moment(x,Torque,rg,rs,vbr,phi,p,b,q)
% 1, 2, 3, 4, 5, 6,7,8,9
However everytime you call BENDING_MOMENT you only call it with six input arguments:
[BM_min,~,~] = bending_moment(x,Torque_min,r_gear,phi,b,t);
% 1, 2, 3, 4,5,6
[BM_max, Loads, Reactions] = bending_moment(x,Torque_max,r_gear,phi,b,t);
% 1, 2, 3, 4,5,6
Question: if you define a function with nine input arguments, how many inputs do you need to call it with? (hint: nine)
Walter Roberson
Walter Roberson 2022 年 3 月 1 日
Depends on the code for the function. If a function never uses a particular parameter or any after it, then it is not required to pass the parameter or later ones. However that code uses all parameters.
Warning: parameters are positional, not by name. The b that is passed as the 5th parameter will not be matched up to the 8th parameter of the function based on the name matching.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGears についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by