Solve system of linear equations ...matrix output is not as expected

Hi All,
I am trying to solve system of equations, as attached,
I have written a code, but my final matrix is 9*9 however, it should be 3*3....I understand i have 9 unknowns with 9 equations, but i wish to understand how could i solve it..
clearvars;
clc;
syms A11 A12 A13 A21 A22 A23 A31 A32 A33 real;
eq1 = A11*-0.001179+A12*-6.581+A13*0.008718 == -0.5;
eq2 = A12*-0.001179+A22*-6.581+A23*0.008718 == 0;
eq3 = A31*-0.001179+A32*-6.581+A33*0.008718 == 0;
eq4 = A11*-0.00251+A12*0.05848+A13*-0.039518 == 0;
eq5 = A21*-0.00251+A22*0.05848+A23*-0.039518 == -0.5;
eq6 = A31*-0.00251+A32*0.05848+A33*-0.039518 == 0;
eq7 = A11*-0.0051200+A12*0.2779500+A13*0.0001469 == 0;
eq8 = A21*-0.0051200+A22*0.2779500+A23*0.0001469 == 0;
eq9 = A31*-0.0051200+A32*0.2779500+A33*0.0001469 == -0.5;
[A] = equationsToMatrix([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9], [A11, A12, A13, A21, A22,A23, A31, A32, A33]);

 Risposta accettata

A being a 9-by-9 matrix is correct.
syms A11 A12 A13 A21 A22 A23 A31 A32 A33 real;
eq1 = A11*-0.001179+A12*-6.581+A13*0.008718 == -0.5;
eq2 = A12*-0.001179+A22*-6.581+A23*0.008718 == 0;
eq3 = A31*-0.001179+A32*-6.581+A33*0.008718 == 0;
eq4 = A11*-0.00251+A12*0.05848+A13*-0.039518 == 0;
eq5 = A21*-0.00251+A22*0.05848+A23*-0.039518 == -0.5;
eq6 = A31*-0.00251+A32*0.05848+A33*-0.039518 == 0;
eq7 = A11*-0.0051200+A12*0.2779500+A13*0.0001469 == 0;
eq8 = A21*-0.0051200+A22*0.2779500+A23*0.0001469 == 0;
eq9 = A31*-0.0051200+A32*0.2779500+A33*0.0001469 == -0.5;
equations = [eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9];
v = [A11, A12, A13, A21, A22,A23, A31, A32, A33];
[A, b] = equationsToMatrix(equations, v);
Let's attempt to recreate the original equations using A and b.
A*v.' == b
ans = 
equations.'
ans = 
Those look like they match to me. Now to solve for v:
v2 = A\b
v2 = 
vpa(A*v2-b, 5)
ans = 

3 Commenti

Thanks for your prompt reply..
I think, I meant another thing, as I will write below:
sol = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9], [A11, A12, A13, A21, A22, A23, A31, A32, A33]);
A11Sol = double(sol.A11);
A12Sol = double(sol.A12);
A13Sol = double(sol.A13);
A21Sol = double(sol.A21);
A22Sol = double(sol.A22);
A23Sol = double(sol.A23);
A31Sol = double(sol.A31);
A32Sol = double(sol.A32);
A33Sol = double(sol.A33);
C=[A11Sol A12Sol A13Sol; A21Sol A22Sol A23Sol;A31Sol A32Sol A33Sol];
May I just ask if my new modifications do what is correct ?
syms A11 A12 A13 A21 A22 A23 A31 A32 A33 real;
eq1 = A11*-0.001179+A12*-6.581+A13*0.008718 == -0.5;
eq2 = A12*-0.001179+A22*-6.581+A23*0.008718 == 0;
eq3 = A31*-0.001179+A32*-6.581+A33*0.008718 == 0;
eq4 = A11*-0.00251+A12*0.05848+A13*-0.039518 == 0;
eq5 = A21*-0.00251+A22*0.05848+A23*-0.039518 == -0.5;
eq6 = A31*-0.00251+A32*0.05848+A33*-0.039518 == 0;
eq7 = A11*-0.0051200+A12*0.2779500+A13*0.0001469 == 0;
eq8 = A21*-0.0051200+A22*0.2779500+A23*0.0001469 == 0;
eq9 = A31*-0.0051200+A32*0.2779500+A33*0.0001469 == -0.5;
equations = [eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9];
v = [A11, A12, A13, A21, A22,A23, A31, A32, A33];
sol = solve(equations, v);
Let's check by substituting back into the original equations.
check = subs(equations, sol)
check = 
Looks good to me. 0 is equal to 0 and -1/2 is equal to -1/2. In addition:
all(isAlways(check))
ans = logical
1
isAlways says that all the elements in check are always true.
Thanks I see, but I am just afraid as the answer should has some zeros elements,
but thanks again

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by