MATLAB: Trying to solve an integration with several functions, each of which is dependent upon a single variable

integral

Hello,
I am attempting to perform an integration using the following formulas:
strain = @(x) (eb-et)/h*x+et;
Cstress = @(x) -Cf*(2*strain(x)/Cec-(strain(x)/Cec).^2);
Cforcef = @(x) Cphi*b*Cstress(x)/1000;
Cmomentf = @(x) Cforcef(x)*(h/2-x)/1000;
All variables are defined except for x. I then perform the following integration:
Caxial = integral(Cforcef,0,limit);
Cmoment = integral(Cmomentf,0,limit);
The first one (Caxial) works fine, however the second (Cmoment) gives me the following error:
Error using *
Inner matrix dimensions must agree.
Error in @(x)Cphi*b*Cstress(x)*(h/2-x)/1000
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 89)
Q = integralCalc(fun,a,b,opstruct);
Does anyone know why this is?
Thank you for your help!

Best Answer

CForcef(x) returns a vector if x is a vector. (h/2-x) returns a vector if x is a vector. You ask for matrix multiplication, "*" between the two vectors. That could only work if one of the vectors is a row vector and the other is a column vector, because interior dimensions must be the same for matrix multipication. (A x B) * (C x D) is only allowed if B = C, so in the case of (1xN) * (1xN), that would require N = 1.
Perhaps you want .* instead of *