Getting error is this code, there are multiple input values of "betasqr" and "sbar" for multiple output values of Wbar, Fbar, fbar and Ybar.

2 views (last 30 days)
betasqr = [0.2 0.4];
gamma = 0.3;
psi = 0.001;
mu = 1.0;
sbar = [1/0.02 1/0.04];
a = 2;
% Steps for finding dimensionless load carrying capacity (Wbar) of the bearing
hbar = @(x) a - a.*x + x;
A = @(x) 4 .* (hbar(x) .^ 3) + sbar .* (hbar(x) .^ 4) - sbar.*betasqr.*gamma .* (hbar(x) .^ 2) .* sqrt(x .* (1-x)) ;
B = @(x) (1 + sbar .* hbar(x)) .* (1 - betasqr .* sqrt(x .* (1-x)));
G = @(x) 12 * psi + A(x) ./ B(x);
Z = @(x) 12 .* hbar(x) + 6.*sbar .* (hbar(x) .^ 2) - 2.*sbar.*betasqr.*gamma .* sqrt(x .* (1-x)) ;
E = @(x) Z(x) ./ (1 + sbar .* hbar(x));
C = @(x) E(x) ./ G(x);
IntEbyG = integral(C,0,1);
D = @(x) 1 ./ G(x);
IntGinv = integral(D,0,1);
Q = IntEbyG/IntGinv;
Wdash = @(x) x.*(E(x)-Q) ./ G(x);
IntWdash = integral(Wdash,0,1);
Wbar = (mu/12) - IntWdash
% Steps for finding dimensionless frictional force (Fbar) of the slider
I = @(x) hbar(x) .* (2 + sbar .* hbar(x)) .* (E(x) - Q );
J = @(x) 2 .* G(x) .* (1 + sbar .* hbar(x)) .* (1 - betasqr .* sqrt(x .* (1-x)));
Fdash = @(x) (sbar ./ (1 + sbar .* hbar(x))) + I(x) ./ J(x);
Fbar = integral(Fdash,0,1)
% Steps for finding coefficient of friction (fbar)
fbar = Fbar/Wbar % Coefficient of friction
% Steps for finding dimensionless form of x coordinate of center of pressure(Ybar)
L = @(x) (x.^2).*(E(x)-Q) ./ G(x);
IntL = integral(L,0,1);
Ybar = ((mu/24)-(0.5*IntL)) / Wbar
getting the following error:
Arrays have incompatible sizes for this operation.
Error in table1inclinea>@(x)12.*hbar(x)+6.*sbar.*(hbar(x).^2)-2.*sbar.*betasqr.*gamma.*sqrt(x.*(1-x)) (line 13)
Z = @(x) 12 .* hbar(x) + 6.*sbar .* (hbar(x) .^ 2) - 2.*sbar.*betasqr.*gamma .* sqrt(x .* (1-x)) ;
Error in table1inclinea>@(x)Z(x)./(1+sbar.*hbar(x)) (line 14)
E = @(x) Z(x) ./ (1 + sbar .* hbar(x));
Error in table1inclinea>@(x)E(x)./G(x) (line 15)
C = @(x) E(x) ./ G(x);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in table1inclinea (line 16)
IntEbyG = integral(C,0,1);

Answers (1)

Ramtej
Ramtej on 8 Sep 2023
Hi Avinash,
I understand thart you are trying to find dimensionless load by integrating your custom anonymous functions.
The "integral(C,0,1)" function computes the integration by passing the array of "x" values spaced between (0,1) to the function "C".
When the command "IntEbyG = integral(C,0,1);" is executed
  • Function "C" calls "E" which in turn calls "Z",
  • "Z" calls "hbar" which returns the output with the size same as input
The error occurs when you try to compute "6.*sbar .* (hbar(x) .^ 2)", where "sbar" is of size (1,2) and "(hbar(x).^ 2)" is of size (1, n). It's important to note that you cannot multiply two row vectors of different sizes (greater than 1).
To resolve this issue, you can refer to the "Compatible Array Sizes for Basic Operations" documentation, which provides a detailed view on compatible sizes for basic operations and redefine your function accordingly.
Hope this resolves your query!

Categories

Find more on Behavior and Psychophysics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!