solve a equation system with a 1xn matrix

Hello,
I got a problem with my code:
FF = 100
psi1 = [1:148]
syms G7_x G7_y C_x C_y D_x D_y
g01 = D_x+FF*cos(psi1) == 0
g02 = D_y+FF*sin(psi1) == 0
g1 = G7_x-FF*cos(psi1) == 0
g2 = G7_y-FF*sin(psi1) == 0
g3 = -G7_x-C_x == 0
g4 = -G7_y-C_y == 0
k=zeros(1,148)
l=zeros(1,148)
s=zeros(1,148)
d=zeros(1,148)
f=zeros(1,148)
g=zeros(1,148)
for i=1:148
[sol_G7_x, sol_G7_y, sol_D_x, sol_D_y, sol_C_x, sol_C_y] = vpasolve([g01(i), g02(i), g1(i), g2(i), g3(i), g4(i)],[G7_x, G7_y, D_x, D_y, C_x, C_y])
k(i)=sol_G7_x
l(i)=sol_G7_y
s(i)=sol_D_x
d(i)=sol_D_y
f(i)=sol_C_x
g(i)=sol_C_y
end
The first passing of the loop works and puts out values. After the first passing the code ends with the following error message:
Index exceeds matrix dimensions.
Error in sym/subsref (line 841)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in TESTTEST (line 20)
[sol_G7_x, sol_G7_y, sol_D_x, sol_D_y, sol_C_x, sol_C_y] = vpasolve([g01(i),
g02(i), g1(i), g2(i), g3(i), g4(i)],[G7_x, G7_y, D_x, D_y, C_x, C_y])
I hope anybody can help me. I use the matlab version R2017a.

 Accepted Answer

Your g3 and g4 have only one element each, so when i becomes 2 because of your for loop, you cannot do
[sol_G7_x, sol_G7_y, sol_D_x, sol_D_y, sol_C_x, sol_C_y] = vpasolve([g01(i), g02(i), g1(i), g2(i), g3(i), g4(i)],[G7_x, G7_y, D_x, D_y, C_x, C_y])
because of the attempt to access g3(2) and g4(2)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!