MATLAB: Linsolve A*X=B where B is a vector

linsolve

Hi guys,
I've searched the documentation and the forums about this but haven't found an answer.
I have the following system of linear equations:
syms Exx Eyy Exy
eqn1 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta1) + (0.5*Exy)*sind(2.0*theta1) == B1;
eqn2 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta2) + (0.5*Exy)*sind(2.0*theta2) == B2;
eqn3 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta3) + (0.5*Exy)*sind(2.0*theta3) == B3;
theta1, theta2 and theta3 are constants. I set up the system into a matrix and solve for Exx, Eyy and Exy:
[A, B] = equationsToMatrix([eqn1, eqn2, eqn3], [Exx ,Eyy, Exy]);
X = linsolve(A, B);
This works fine if B1, B2 and B3 are 1×1 constants. However, for my application B can be a 1xN vector. Using B in this context does not produce a solution.
Currently I have the above code under a FOR loop where I solve the system for each value of B1,2,3, and assign the values of Exx, Eyy and Exy into a pre-allocated buffer. This can be very slow, so I'm wondering if there's a way to successfully vectorize linsolve such that it can solve the system for N Exx,yy,xy values based on N B1,2,3 values?
Best regards,
Louis

Best Answer

syms Exx Eyy Exy
eqn1 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta1) + (0.5*Exy)*sind(2.0*theta1) == 0;
eqn2 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta2) + (0.5*Exy)*sind(2.0*theta2) == 0;
eqn3 = 0.5*(Exx + Eyy) + 0.5*(Exx - Eyy)*cosd(2.0*theta3) + (0.5*Exy)*sind(2.0*theta3) == 0;
A = equationsToMatrix([eqn1, eqn2, eqn3], [Exx ,Eyy, Exy]);
B = [B11 B12 B13 B14 ... B1N;
B21 B22 B23 B24 ... B2N;
B31 B32 B33 B34 ... B3N];
X = linsolve(A,B);
Best wishes
Torsten.