Azzera filtri
Azzera filtri

Too many input arguements

18 visualizzazioni (ultimi 30 giorni)
N G
N G il 26 Lug 2024 alle 7:40
Risposto: Karan Singh il 26 Lug 2024 alle 7:56
I have created a code but I am getting the error of too many input arguements, how do I avoid that? The code is a finite difference method solution for thrust pad bearing. I need a 3d graph.
Ro=120.5; % Outer Rad mm
Ri=28.6; % Inner Rad mm
Rr=(Ro+Ri)/2; % Mean Rad mm
Pt=76; % Pad Thickness mm
Nm=36; % Speed rpm
Tm=45150; % Load Kg
theta1=27.13;
rho=889; % Density
mu40=94; % Viscosity at 40
mu100=10.6; % Viscosity at 100
Cp=1960;
%H0=5e-5; % Film Thickness
r=linspace(28.6,1,120.5);
H0=linspace(0,5e-6,5e-5);
theta=linspace(0,1,27.13);
n=50; % No of nodes in r direction
m=50; % No of nodes in theta direction
del_r=1/n;
del_theta=1/m;
eta=52.3;
r_bar=0:del_r:1;
theta_bar=0:del_theta:1;
U_fd=(2*pi*Rr*Nm)/60;
hmax = 0.007; % Maximum wedge thickness
hmin = 0.003; % Minimum wedge thickness
C = (hmax + hmin)/2; % average wedge thickness
fun_ihbar = @(r_bar,r)((hmax - (hmax - hmin)*r_bar)/C);
fun_jhbar = @(theta_bar,theta)((hmax - (hmax - hmin)*theta_bar)/C);
fun_hhalf = @(h)(-((h(2)-h(1))/2) + h(2)); % fluid film half node (i-0.5)
fun_hhalf2 = @(h)(((h(2)-h(1))/2) + h(1)); % fluid film half node (i+0.5)
h_bar_i_fd=fun_ihbar(r_bar,r); % non dimensionalized film thickness
h_bar_j_fd=fun_jhbar(theta_bar,theta);
h_m_i_fd=zeros(size(r_bar,2),1); % non dimensionalized half node i-0.5
for i=2:length(h_bar_i_fd)-1
h_m_i_fd(i)=fun_hhalf([h_bar_i_fd(i-1) h_bar_i_fd(i)]);
end
h_p_i_fd=zeros(size(r_bar,2),1); % non dimensionalized half node i+0.5
for i=2:length(h_bar_i_fd)-1
h_p_i_fd(i)=fun_hhalf2([h_bar_i_fd(i) h_bar_i_fd(i+1)]);
end
h_m_j_fd=zeros(size(theta_bar,2),1); % non dimensionalized half node i-0.5
for j=2:length(h_bar_j_fd)-1
h_m_j_fd(i)=fun_hhalf([h_bar_j_fd(j-1) h_bar_j_fd(j)]);
end
h_p_j_fd=zeros(size(theta_bar,2),1); % non dimensionalized half node i+0.5
for j=2:length(h_bar_j_fd)-1
h_p_j_fd(i)=fun_hhalf2([h_bar_j_fd(j) h_bar_j_fd(j+1)]);
end
h_i_fd=(h_bar_i_fd.^3);
h_plus_i_fd=(h_p_i_fd.^3);
h_minus_i_fd=(h_m_i_fd.^3);
h_j_fd=(h_bar_j_fd.^3);
h_plus_j_fd=(h_p_j_fd.^3);
h_minus_j_fd=(h_m_j_fd.^3);
r1_const=1/Rr;
iter=1000;
p_bar_fd=zeros(length(r_bar),length(theta_bar));
A_fun = @(h_p,h_m,h)(Rr*h_p/(Rr*h_p + Rr*h_m + 2*r1_const*h));
B_fun = @(h_p,h_m,h)(Rr*h_m/(Rr*h_p + Rr*h_m + 2*r1_const*h));
C_fun = @(h_p,h_m,h)((r1_const*h)/(Rr*h_p + Rr*h_m + 2*r1_const*h));
E_fun = @(h_p,h_m,h_b1,h_b2,h)(((-(6*eta*U_fd*del_r*del_r)/(2*del_theta))*(h_b2-h_b1))/(Rr*h_p+Rr*h_m+2*r1_const*h));
p_init=p_bar_fd;
error_target=0.0001;
h=waitbar(0, 'Please wait....');
for k=1:iter
for j=2:size(p_bar_fd,2)-1
for i=2:size(p_bar_fd,1)-1
p_bar_fd(i,j)=A_fun(h_plus_i_fd(i),h_minus_i_fd(i),h_i_fd(i),h_plus_j_fd(j),h_minus_j_fd(j),h_j_fd(j))*p_bar_fd(i+1,j)+...
B_fun(h_plus_i_fd(i),h_minus_i_fd(i),h_i_fd(i),h_plus_j_fd(j),h_minus_j_fd(j),h_j_fd(j))*p_bar_fd(i-1,j)+...
C_fun(h_plus_i_fd(i),h_minus_i_fd(i),h_i_fd(i),h_plus_j_fd(j),h_minus_j_fd(j),h_j_fd(j))*p_bar_fd(i,j+1)+...
C_fun(h_plus_i_fd(i),h_minus_i_fd(i),h_i_fd(i),h_plus_j_fd(j),h_minus_j_fd(j),h_j_fd(j))*p_bar_fd(i,j-1)+...
E_fun(h_plus_i_fd(i),h_minus_i_fd(i),h_bar_i_fd(i-1),h_bar_i_fd(i+1),h_i_fd(i),h_plus_j_fd(j),h_minus_j_fd(j),h_bar_j_fd(j-1),h_bar_j_fd(j+1),h_j_fd(j));
end
end
error=(sum(p_bar_fd(:))-sum(p_init(:)))/sum(p_bar_fd(:));
p_init=p_bar_fd;
if error<error_target
break;
end
waitbar(k/iter);
end
close(h)
figure(1)
P_scale=(1000*p_bar_fd*6*eta*U_fd)./(Rr);
r_scale=r_bar.*Rr;
theta_scale=theta_bar.*theta1;
colormap(jet);
surf(theta_scale,r_scale,P_scale);
title('Pressure Profile');
xlabel('theta(rad)');
ylabel('R(mm)');
zlabel('Pressure');
  1 Commento
Aquatris
Aquatris il 26 Lug 2024 alle 7:45
Modificato: Aquatris il 26 Lug 2024 alle 7:46
You defined Afun to accept 3 inputs. But in your nested for loop, you are calling it with 6 inputs. What exactly are you trying to do there (not interested in the physics, code wise what do you expect A_fun to do with 6 inputs when you defined it as a function that expects 3 input )?
Same thing for B_fun C_fun E_fun functions as well. You define them to expect n inputs and then call them with 2*n inputs.

Accedi per commentare.

Risposte (1)

Karan Singh
Karan Singh il 26 Lug 2024 alle 7:56
The error "too many input arguments" occurs because some of your anonymous functions are defined with more parameters than you are passing when calling them.
Also I think that correct the loop variables in h_m_j_fd and h_p_j_fd to use j instead of i, cause I am not getting a 3d graph...... have a look at them.
Ro = 120.5; % Outer Radius in mm
Ri = 28.6; % Inner Radius in mm
Rr = (Ro + Ri) / 2; % Mean Radius in mm
Pt = 76; % Pad Thickness in mm
Nm = 36; % Speed in rpm
Tm = 45150; % Load in Kg
theta1 = 27.13; % Angular extent in degrees
rho = 889; % Density
mu40 = 94; % Viscosity at 40 degrees
mu100 = 10.6; % Viscosity at 100 degrees
Cp = 1960; % Specific heat capacity
r = linspace(Ri, Ro, 50); % Radial divisions
theta = linspace(0, theta1, 50); % Angular divisions
n = 50; % Number of nodes in r direction
m = 50; % Number of nodes in theta direction
del_r = 1 / n;
del_theta = 1 / m;
eta = 52.3; % Dynamic viscosity
r_bar = 0:del_r:1;
theta_bar = 0:del_theta:1;
U_fd = (2 * pi * Rr * Nm) / 60;
hmax = 0.007; % Maximum wedge thickness
hmin = 0.003; % Minimum wedge thickness
C = (hmax + hmin) / 2; % Average wedge thickness
fun_ihbar = @(r_bar)((hmax - (hmax - hmin) * r_bar) / C);
fun_jhbar = @(theta_bar)((hmax - (hmax - hmin) * theta_bar) / C);
fun_hhalf = @(h)(-((h(2) - h(1)) / 2) + h(2)); % Fluid film half node (i-0.5)
fun_hhalf2 = @(h)(((h(2) - h(1)) / 2) + h(1)); % Fluid film half node (i+0.5)
h_bar_i_fd = fun_ihbar(r_bar); % Non-dimensionalized film thickness
h_bar_j_fd = fun_jhbar(theta_bar);
h_m_i_fd = zeros(size(r_bar, 2), 1); % Non-dimensionalized half node i-0.5
for i = 2:length(h_bar_i_fd) - 1
h_m_i_fd(i) = fun_hhalf([h_bar_i_fd(i - 1) h_bar_i_fd(i)]);
end
h_p_i_fd = zeros(size(r_bar, 2), 1); % Non-dimensionalized half node i+0.5
for i = 2:length(h_bar_i_fd) - 1
h_p_i_fd(i) = fun_hhalf2([h_bar_i_fd(i) h_bar_i_fd(i + 1)]);
end
h_m_j_fd = zeros(size(theta_bar, 2), 1); % Non-dimensionalized half node i-0.5
for j = 2:length(h_bar_j_fd) - 1
h_m_j_fd(j) = fun_hhalf([h_bar_j_fd(j - 1) h_bar_j_fd(j)]);
end
h_p_j_fd = zeros(size(theta_bar, 2), 1); % Non-dimensionalized half node i+0.5
for j = 2:length(h_bar_j_fd) - 1
h_p_j_fd(j) = fun_hhalf2([h_bar_j_fd(j) h_bar_j_fd(j + 1)]);
end
h_i_fd = (h_bar_i_fd .^ 3);
h_plus_i_fd = (h_p_i_fd .^ 3);
h_minus_i_fd = (h_m_i_fd .^ 3);
h_j_fd = (h_bar_j_fd .^ 3);
h_plus_j_fd = (h_p_j_fd .^ 3);
h_minus_j_fd = (h_m_j_fd .^ 3);
r1_const = 1 / Rr;
iter = 1000;
p_bar_fd = zeros(length(r_bar), length(theta_bar));
A_fun = @(h_p, h_m, h)(Rr * h_p / (Rr * h_p + Rr * h_m + 2 * r1_const * h));
B_fun = @(h_p, h_m, h)(Rr * h_m / (Rr * h_p + Rr * h_m + 2 * r1_const * h));
C_fun = @(h_p, h_m, h)((r1_const * h) / (Rr * h_p + Rr * h_m + 2 * r1_const * h));
E_fun = @(h_p, h_m, h_b1, h_b2, h)(((-(6 * eta * U_fd * del_r * del_r) / (2 * del_theta)) * (h_b2 - h_b1)) / (Rr * h_p + Rr * h_m + 2 * r1_const * h));
p_init = p_bar_fd;
error_target = 0.0001;
h = waitbar(0, 'Please wait....');
for k = 1:iter
for j = 2:size(p_bar_fd, 2) - 1
for i = 2:size(p_bar_fd, 1) - 1
p_bar_fd(i, j) = A_fun(h_plus_i_fd(i), h_minus_i_fd(i), h_i_fd(i)) * p_bar_fd(i + 1, j) + ...
B_fun(h_plus_i_fd(i), h_minus_i_fd(i), h_i_fd(i)) * p_bar_fd(i - 1, j) + ...
C_fun(h_plus_j_fd(j), h_minus_j_fd(j), h_j_fd(j)) * p_bar_fd(i, j + 1) + ...
C_fun(h_plus_j_fd(j), h_minus_j_fd(j), h_j_fd(j)) * p_bar_fd(i, j - 1) + ...
E_fun(h_plus_i_fd(i), h_minus_i_fd(i), h_bar_i_fd(i - 1), h_bar_i_fd(i + 1), h_i_fd(i));
end
end
error = (sum(p_bar_fd(:)) - sum(p_init(:))) / sum(p_bar_fd(:));
p_init = p_bar_fd;
if error < error_target
break;
end
waitbar(k / iter);
end
close(h);
figure(1);
P_scale = (1000 * p_bar_fd * 6 * eta * U_fd) / Rr;
r_scale = r_bar .* Rr;
theta_scale = theta_bar .* theta1;
colormap(jet);
surf(theta_scale, r_scale, P_scale);
title('Pressure Profile');
xlabel('theta (rad)');
ylabel('R (mm)');
zlabel('Pressure');
Code is not able to run here but here is the result as a sc.

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by