I have 2 , 1×20 Matrices. Say,Matrix A and B are my 2 Matrices. What I would like to do is Sum of (A_i + A_i+1)*(B_i + B_i+1). Where A_i @ i=0 is the first term of matrix A and A_i+1 the term after that for all 20 terms. Same for B. How could I do that?
MATLAB: Trying to do a summation of matrices
matrixsumation
Related Solutions
solve() generically outside of the loop and then subs() or matlabFunction() to get code executed for each loop instance.
t = roots( [Coeff(6)*A(i, 1)^5+Coeff(11)*A(i, 1)^4*A(i, 2)+Coeff(15)*A(i, 1)^3*A(i, 2)^2+Coeff(18)*A(i, 1)^2*A(i, 2)^3+Coeff(20)*A(i, 1)*A(i, 2)^4+Coeff(21)*A(i, 2)^5, (5*Coeff(6)*B(i, 1)+Coeff(11)*B(i, 2)+Coeff(5))*A(i, 1)^4+(2*(2*Coeff(11)*B(i, 1)+Coeff(15)*B(i, 2)+(1/2)*Coeff(10)))*A(i, 1)^3*A(i, 2)+(3*Coeff(15)*B(i, 1)+3*Coeff(18)*B(i, 2)+Coeff(14))*A(i, 1)^2*A(i, 2)^2+(2*Coeff(18)*B(i, 1)+4*Coeff(20)*B(i, 2)+Coeff(17))*A(i, 1)*A(i, 2)^3+(Coeff(20)*B(i, 1)+5*Coeff(21)*B(i, 2)+Coeff(19))*A(i, 2)^4, (10*Coeff(6)*B(i, 1)^2+Coeff(15)*B(i, 2)^2+(4*Coeff(11)*B(i, 2)+4*Coeff(5))*B(i, 1)+Coeff(10)*B(i, 2)+Coeff(4))*A(i, 1)^3+(3*(2*Coeff(11)*B(i, 1)^2+Coeff(18)*B(i, 2)^2+(2*Coeff(15)*B(i, 2)+Coeff(10))*B(i, 1)+(2/3)*Coeff(14)*B(i, 2)+(1/3)*Coeff(9)))*A(i, 1)^2*A(i, 2)+(3*Coeff(15)*B(i, 1)^2+6*Coeff(20)*B(i, 2)^2+(6*Coeff(18)*B(i, 2)+2*Coeff(14))*B(i, 1)+3*Coeff(17)*B(i, 2)+Coeff(13))*A(i, 1)*A(i, 2)^2+(Coeff(18)*B(i, 1)^2+10*Coeff(21)*B(i, 2)^2+(4*Coeff(20)*B(i, 2)+Coeff(17))*B(i, 1)+4*Coeff(19)*B(i, 2)+Coeff(16))*A(i, 2)^3, (10*Coeff(6)*B(i, 1)^3+Coeff(18)*B(i, 2)^3+(6*Coeff(11)*B(i, 2)+6*Coeff(5))*B(i, 1)^2+Coeff(14)*B(i, 2)^2+(3*Coeff(15)*B(i, 2)^2+3*Coeff(10)*B(i, 2)+3*Coeff(4))*B(i, 1)+Coeff(9)*B(i, 2)+Coeff(3))*A(i, 1)^2+(4*Coeff(11)*B(i, 1)^3+4*Coeff(20)*B(i, 2)^3+(6*Coeff(15)*B(i, 2)+3*Coeff(10))*B(i, 1)^2+3*Coeff(17)*B(i, 2)^2+(6*Coeff(18)*B(i, 2)^2+4*Coeff(14)*B(i, 2)+2*Coeff(9))*B(i, 1)+2*Coeff(13)*B(i, 2)+Coeff(8))*A(i, 1)*A(i, 2)+(Coeff(15)*B(i, 1)^3+10*Coeff(21)*B(i, 2)^3+(3*Coeff(18)*B(i, 2)+Coeff(14))*B(i, 1)^2+6*Coeff(19)*B(i, 2)^2+(6*Coeff(20)*B(i, 2)^2+3*Coeff(17)*B(i, 2)+Coeff(13))*B(i, 1)+3*Coeff(16)*B(i, 2)+Coeff(12))*A(i, 2)^2, (5*Coeff(6)*A(i, 1)+Coeff(11)*A(i, 2))*B(i, 1)^4+(Coeff(20)*A(i, 1)+5*Coeff(21)*A(i, 2))*B(i, 2)^4+(4*Coeff(5)*A(i, 1)+Coeff(10)*A(i, 2)+(4*Coeff(11)*A(i, 1)+2*Coeff(15)*A(i, 2))*B(i, 2))*B(i, 1)^3+(Coeff(17)*A(i, 1)+4*Coeff(19)*A(i, 2))*B(i, 2)^3+((3*Coeff(15)*A(i, 1)+3*Coeff(18)*A(i, 2))*B(i, 2)^2+3*Coeff(4)*A(i, 1)+Coeff(9)*A(i, 2)+(3*Coeff(10)*A(i, 1)+2*Coeff(14)*A(i, 2))*B(i, 2))*B(i, 1)^2+(Coeff(13)*A(i, 1)+3*Coeff(16)*A(i, 2))*B(i, 2)^2+Coeff(2)*A(i, 1)+Coeff(7)*A(i, 2)+A(i, 3)+((2*Coeff(18)*A(i, 1)+4*Coeff(20)*A(i, 2))*B(i, 2)^3+(2*Coeff(14)*A(i, 1)+3*Coeff(17)*A(i, 2))*B(i, 2)^2+2*Coeff(3)*A(i, 1)+Coeff(8)*A(i, 2)+(2*Coeff(9)*A(i, 1)+2*Coeff(13)*A(i, 2))*B(i, 2))*B(i, 1)+(Coeff(8)*A(i, 1)+2*Coeff(12)*A(i, 2))*B(i, 2), Coeff(6)*B(i, 1)^5+Coeff(21)*B(i, 2)^5+(Coeff(11)*B(i, 2)+Coeff(5))*B(i, 1)^4+Coeff(19)*B(i, 2)^4+(Coeff(15)*B(i, 2)^2+Coeff(10)*B(i, 2)+Coeff(4))*B(i, 1)^3+Coeff(16)*B(i, 2)^3+(Coeff(18)*B(i, 2)^3+Coeff(14)*B(i, 2)^2+Coeff(9)*B(i, 2)+Coeff(3))*B(i, 1)^2+Coeff(12)*B(i, 2)^2-Thickness+(Coeff(20)*B(i, 2)^4+Coeff(17)*B(i, 2)^3+Coeff(13)*B(i, 2)^2+Coeff(8)*B(i, 2)+Coeff(2))*B(i, 1)+Coeff(7)*B(i, 2)+B(i, 3)+Coeff(1) ] );
and then do the filtering like you had before.
I haven't tried this, but it sounds straightforward.
Decision variables: x(1) = x, x(2) = y, x(3) = R.
100 nonlinear inequality constraints: (x(1) - a(i))^2 + (x(2) - b(i))^2 - R^2 <= 0
Objective function: R = x(3)
Bounds: ll = min(min([a,b])), mm = max(max([a,b]))
lb = [ll,ll,0] , ub = [mm,mm,Inf]
Call fmincon from a reasonable start point, such as [(ll+mm)/2,(ll+mm)/2,abs(mm)]
Alan Weiss
MATLAB mathematical toolbox documentation
Best Answer