I have a matrix equation system and I need help to solve it
Mostrar comentarios más antiguos
So I have these 3, 7*1 variable matrices in those system of equations and C{1,1} and C{1,2} are 7*7 matrices and they are constant, also S_1 to S_15 are 1*7 constant matrices. Problem is, it gives me U=0, W=0 and PHI=0 and it doesnt calculate the variables in those U, W and PHI matrices.
syms U [7 1]
U;
syms W [7 1]
W;
syms PHI [7 1]
PHI;
syms U W PHI
eq1 = (S_1*C{1,2}*U)+(S_2*C{1,1}*U)-(S_3*U)+(S_4*C{1,2}*W)+(S_5*C{1,1}*W) == 0;
eq2 = (S_6*C{1,2}*PHI)+(S_7*C{1,1}*PHI)+(S_8*PHI)-(S_9*C{1,1}*W) == 0;
eq3 = (S_10*C{1,2}*W)+(S_11*C{1,1}*W)+(S_12*C{1,1}*PHI)+(S_13*PHI)+(S_14*C{1,1}*U)...
-(S_15*U) == 0;
[U, W, PHI] = solve([eq1, eq2, eq3],[U, W, PHI])
44 comentarios
You are overwriting the variables U, W and PHI. Remove the line where you define them again.
Note that this doesn't guarantee obtaining a solution as there are 21 unknowns and 3 equations.
syms U [7 1]
syms W [7 1]
syms PHI [7 1]
U
W
PHI
%Remove this line
%This line overwrites U, W and PHI from 7x1 syms variable
%to 1x1 syms variable
syms U W PHI
U
W
PHI
mahdi
el 24 de Mayo de 2023
Dyuman Joshi
el 25 de Mayo de 2023
"Note that this doesn't guarantee obtaining a solution as there are 21 unknowns and 3 equations."
I said this in an above comment.
How can you solve for 21 unknowns when you only have 3 equations?
There are 3*7 equations because each eq_i is made up of 7 equations. I think it should suffice to substitute the 0 of the right-hand side by a 7x1 vector of 0's and keep the output variables general (as "UWPHI", e.g.).
mahdi
el 25 de Mayo de 2023
Works for me - although the solution looks boring:
U_g1 = 0; U_g2 = 0; U_g3 = 0;
B1 = [-0.0493 -0.0490 -0.0455 -0.0348 -0.0188 -0.0051 0];
W0 = B1; Nu = 0.285;
A_11 = 64; A_55 = 37; D_11 = 2;
syms U [7 1]
syms W [7 1]
syms PHI [7 1]
for z=[0.03349]
for v=[-0.0493]
for q=[-0.0016]
C11 = rand(7);
C12 = rand(7);
eq1 = (((2*A_11).*z.^2)*C11*U)+(((2*A_11).*z)*C11*U)-((2*A_11)*U)+...
(((A_11.*v).*z)*C12*W)+((((A_11-(Nu*A_11)).*q).*z)*C11*W) == zeros(7,1);
eq2 = ((D_11.*z.^2)*C12*PHI)+((D_11.*z)*C11*PHI)+(((D_11+A_55).*z)*PHI)...
-((A_55.*z.^2)*C11*W) == zeros(7,1);
eq3 = ((((2*A_55).*z)+((2*A_11.*U_g2).*z)+((A_11.*v.^2).*z)+...
(2*Nu*A_11.*U_g3))*C12*W)+(((2*A_55)+(2*A_11.*U_g2)...
+((2*A_11.*U_g1).*z)+(A_11.*q.^2)-(((A_11.*W0).*q).*z))*C11*W)+...
(((2*A_55).*z)*C11*PHI)+((2*A_55)*PHI)+(((2*Nu*A_11)-((2*A_11.*W0).*z))*C11*U)...
-((2*Nu*A_11.*W0)*U) == zeros(7,1);
UWPHI = solve([eq1, eq2, eq3],[U, W, PHI])
end
end
end
Yes, and if you type
UWPHI.U1
you get the solution for U(1) and so on.
But only for the last combination of z,v,q since you don't save UWPHI in a 3d cell array UWPHI{i,j,k} depending on z(i), v(j) and q(k).
mahdi
el 25 de Mayo de 2023
The solutions are all 0 because you have a system of the form A*[U,V,PHI] = 0.
If you change the right-hand sides to something different from 0, you will get more interesting solutions.
U_g1 = 0; U_g2 = 0; U_g3 = 0;
B1 = [-0.0493 -0.0490 -0.0455 -0.0348 -0.0188 -0.0051 0];
W0 = B1; Nu = 0.285;
A_11 = 64; A_55 = 37; D_11 = 2;
syms U[7 1]
syms W[7 1]
syms PHI[7 1]
Z = [0,0.03349,0.1250,0.2500,0.3750,0.4665,0.5000];
V = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0];
Q = [0,-0.0016,-0.0060,-0.0111,-0.0145,-0.0156,-0.0157];
for iz = 1:numel(Z)
z = Z(iz);
for iv = 1:numel(V)
v = V(iv);
for iq = 1:numel(Q)
q = Q(iq);
eq1 = (((2*A_11).*z.^2)*C{1,2}*U)+(((2*A_11).*z)*C{1,1}*U)-((2*A_11)*U)+...
(((A_11.*v).*z)*C{1,2}*W)+((((A_11-(Nu*A_11)).*q).*z)*C{1,1}*W) == zeros(7,1);
eq2 = ((D_11.*z.^2)*C{1,2}*PHI)+((D_11.*z)*C{1,1}*PHI)+(((D_11+A_55).*z)*PHI)...
-((A_55.*z.^2)*C{1,1}*W) == zeros(7,1);
eq3 = ((((2*A_55).*z)+((2*A_11.*U_g2).*z)+((A_11.*v.^2).*z)+...
(2*Nu*A_11.*U_g3))*C{1,2}*W)+(((2*A_55)+(2*A_11.*U_g2)...
+((2*A_11.*U_g1).*z)+(A_11.*q.^2)-(((A_11.*W0).*q).*z))*C{1,1}*W)+...
(((2*A_55).*z)*C{1,1}*PHI)+((2*A_55)*PHI)+(((2*Nu*A_11)-((2*A_11.*W0).*z))*C{1,1}*U)...
-((2*Nu*A_11.*W0)*U) == zeros(7,1);
UWPHI{iz,iv,iq} = solve([eq1, eq2, eq3],[U, W, PHI])
end
end
end
Chunru
el 26 de Mayo de 2023
==> There are 3*7 equations because each eq_i is made up of 7 equations. I think it should suffice to substitute the 0 of the right-hand side by a 7x1 vector of 0's and keep the output variables general (as "UWPHI", e.g.).
eq1 = (S_1*C{1,2}*U)+(S_2*C{1,1}*U)-(S_3*U)+(S_4*C{1,2}*W)+(S_5*C{1,1}*W) == 0;
This is a single equation instead of 7 eqations. Since S_1 is 1x7, C{1,2} is 7x7 and U is 7x1, S_1*C{1,2} is a constant 1x7 vector. Therefore S_1*C{1,2}*U)+(S_2*C{1,1}*U is a linear combination of 7 elements of U. Similarly for the other terms in the left side of eq1. Therefore this is a single equation of U and W (with 14 unknows).
I don't understand what you mean by "get the U1, W1 and PHI1 from the Q1, V1 and Q2, V2 and Q3, V3".
You have defined 99 equations for 21 unknowns.
Please explain what you are trying to do.
C{1,1} = rand(7);
C{1,2} = rand(7);
syms U [7,1]
Q1 = sum(C{1,1}*U);
V1 = sum(C{1,2}*U);
syms W [7,1]
Q2 = sum(C{1,1}*W);
V2 = sum(C{1,2}*W);
syms PHI [7,1]
Q3 = sum(C{1,1}*PHI);
V3 = sum(C{1,2}*PHI);
z1 = [0,0.03349,0.1250,0.2500,0.3750,0.4665,0.5000];
z2 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0];
z3 = [0,-0.0016,-0.0060,-0.0111,-0.0145,-0.0156,-0.0157];
B1 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0];
U_g1 = 0; U_g2 = 0; U_g3 = 0;
W0 = B1; Nu = 0.285;
A_11 = 64; A_55 = 37; D_11 = 2;
eq1 = (((2*A_11).*z1.^2)*V1)+(((2*A_11).*z1)*Q1)-((2*A_11)*U)+...
(((A_11.*z2).*z1)*V2)+((((A_11-(Nu*A_11)).*z3).*z1)*Q2) == 0
eq2 = ((D_11.*z1.^2)*V3)+((D_11.*z1)*Q3)+(((D_11+A_55).*z1)*PHI)...
-((A_55.*z1.^2)*Q1) == 0
eq3 = (((((2*A_55).*z1)+((2*A_11.*U_g2).*z1)+((A_11.*z2.^2).*z1)+...
(2*Nu*A_11.*U_g3))*V2)+(((2*A_55)+(2*A_11.*U_g2)...
+((2*A_11.*U_g1).*z1)+(A_11.*z3.^2)+((2*A_11).*U_g3)+...
((2*A_11).*z1))*Q1)+(((2*A_55).*z1)*Q3)+((2*A_55)*PHI)) == ...
(((((2*Nu*A_11).*U_g2).*z1)+((A_11.*z3.^2).*z1)...
+((2*Nu*A_11).*U_g3)).*B1)
size(eq1)
size(eq2)
size(eq3)
Maybe you mean
C{1,1} = rand(7);
C{1,2} = rand(7);
syms U [7,1]
Q1 = sum(C{1,1}*U);
V1 = sum(C{1,2}*U);
syms W [7,1]
Q2 = sum(C{1,1}*W);
V2 = sum(C{1,2}*W);
syms PHI [7,1]
Q3 = sum(C{1,1}*PHI);
V3 = sum(C{1,2}*PHI);
z1 = [0,0.03349,0.1250,0.2500,0.3750,0.4665,0.5000].';
z2 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0].';
z3 = [0,-0.0016,-0.0060,-0.0111,-0.0145,-0.0156,-0.0157].';
B1 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0].';
U_g1 = 0; U_g2 = 0; U_g3 = 0;
W0 = B1; Nu = 0.285;
A_11 = 64; A_55 = 37; D_11 = 2;
eq1 = (((2*A_11).*z1.^2)*V1)+(((2*A_11).*z1)*Q1)-((2*A_11)*U)+...
(((A_11.*z2).*z1)*V2)+((((A_11-(Nu*A_11)).*z3).*z1)*Q2) == 0
eq2 = ((D_11.*z1.^2)*V3)+((D_11.*z1)*Q3)+(((D_11+A_55).*z1).*PHI)...
-((A_55.*z1.^2)*Q1) == 0
eq3 = (((((2*A_55).*z1)+((2*A_11.*U_g2).*z1)+((A_11.*z2.^2).*z1)+...
(2*Nu*A_11.*U_g3))*V2)+(((2*A_55)+(2*A_11.*U_g2)...
+((2*A_11.*U_g1).*z1)+(A_11.*z3.^2)+((2*A_11).*U_g3)+...
((2*A_11).*z1))*Q1)+(((2*A_55).*z1)*Q3)+((2*A_55)*PHI)) == ...
(((((2*Nu*A_11).*U_g2).*z1)+((A_11.*z3.^2).*z1)...
+((2*Nu*A_11).*U_g3)).*B1)
[A,b] = equationsToMatrix([eq1,eq2,eq3])
rank(A)
rank([A,b])
But as you can see, your linear system A*X = b of 21 equations in 21 unknowns cannot be solved since the right-hand side vector b is not in the column space of the matrix A.
C{1,1} = rand(7);
C{1,2} = rand(7);
syms U [7,1]
Q1 = (sum(C{1,1},1).*U.').';
V1 = (sum(C{1,2},1).*U.').';
syms W [7,1]
Q2 = (sum(C{1,1},1).*W.').';
V2 = (sum(C{1,2},1).*W.').';
syms PHI [7,1]
Q3 = (sum(C{1,1},1).*PHI.').';
V3 = (sum(C{1,2},1).*PHI.').';
z1 = [0,0.03349,0.1250,0.2500,0.3750,0.4665,0.5000].';
z2 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0].';
z3 = [0,-0.0016,-0.0060,-0.0111,-0.0145,-0.0156,-0.0157].';
B1 = [-0.0493,-0.0490,-0.0455,-0.0348,-0.0188,-0.0051,0].';
U_g1 = 0; U_g2 = 0; U_g3 = 0;
W0 = B1; Nu = 0.285;
A_11 = 64; A_55 = 37; D_11 = 2;
eq1 = (((2*A_11).*z1.^2).*V1)+(((2*A_11).*z1).*Q1)-((2*A_11)*U)+...
(((A_11.*z2).*z1).*V2)+((((A_11-(Nu*A_11)).*z3).*z1).*Q2) == 0;
eq2 = ((D_11.*z1.^2).*V3)+((D_11.*z1).*Q3)+(((D_11+A_55).*z1).*PHI)...
-((A_55.*z1.^2).*Q1) == 0;
eq3 = (((((2*A_55).*z1)+((2*A_11.*U_g2).*z1)+((A_11.*z2.^2).*z1)+...
(2*Nu*A_11.*U_g3)).*V2)+(((2*A_55)+(2*A_11.*U_g2)...
+((2*A_11.*U_g1).*z1)+(A_11.*z3.^2)+((2*A_11).*U_g3)+...
((2*A_11).*z1)).*Q1)+(((2*A_55).*z1).*Q3)+((2*A_55).*PHI)) == ...
(((((2*Nu*A_11).*U_g2).*z1)+((A_11.*z3.^2).*z1)...
+((2*Nu*A_11).*U_g3)).*B1);
vars = [U;W;PHI];
[A,b] = equationsToMatrix([eq1,eq2,eq3],vars);
rank(A)
rank([A,b])
sol = A\b
vpa(sol(2)) %U2
vpa(sol(2+7)) %W2
vpa(sol(2+14)) %PHI2
vpa(sol(5)) %U5
vpa(sol(5+7)) %W5
vpa(sol(5+14)) %PHI5
mahdi
el 26 de Mayo de 2023
Walter Roberson
el 26 de Mayo de 2023
z2 = eval(subs(P,r,z1));
Never eval() a symbolic expression. Mathworks does not document any meaning for eval() of a symbolic expression, and you will get errors and unexpected answers sometimes.
Is this the complete form that gives the solution from U_1 to U_7 and W_1 to W_7 and PHI_1 to PHI_7?
Should be so. But as you can see, rank(A) is only 20, not 21. I did not study in detail what implications this might have. It seems that W(1) is arbitrary since z1(1) = z3(1) = 0.
mahdi
el 27 de Mayo de 2023
Dyuman Joshi
el 27 de Mayo de 2023
Use double() on the output.
Torsten
el 27 de Mayo de 2023
I thought z1 is input, not output.
mahdi
el 27 de Mayo de 2023
mahdi
el 27 de Mayo de 2023
Why do you always include code that I cannot execute - thus code that I cannot correct ?
Remove the line
W(1) = 0.005
and set
sol(7+1) = 0.005
This way, you have set W(1) = 0.005.
If you type
Omega(:,8)
in your code, you will see a column of zeros. This means that W(1) can be chosen arbitrarily since it is multiplied by 0 for all equations present.
mahdi
el 29 de Mayo de 2023
{}; % for example only
C{1,1} = rand(7);
C{1,2} = rand(7);
Nu = 0.285; A_11 = 64; A_55 = 37; D_11 = 2; w0c = 0.005; R = 0.5;
A11 = 6.4*10^4; A55 = 3.7*10^4; D11 = 2*10^3;
N = 7; a = 0; b = 0.5;
X1 = a+(b-a)*(1-cos(((1:N)-1)*pi/(N-1)))/2;
syms r
w0 = w0c*cos(pi*r/(2*R));
w0onX1 = double(subs(w0,r,X1));
A = C{1,1}*w0onX1.';
B = C{1,2}*w0onX1.';
B1 = C{1,2}*w0onX1.';
C_1 = cell2mat(C(1));
al = zeros(N);
al(2:N, 1:N) = C_1(2:N, 1:N);
bl = zeros(N);
bl(1:N-1, 1:N) = C_1(1:N-1, 1:N);
syms U [N,1]
syms W [N,1]
syms PHI [N,1]
z1 = X1;
z2 = B.';
z3 = A.';
z4 = B1.';
Ug1 = 0; Ug2 = 0; Ug3 = 0;
atm=((2*A11*z1.^2).*(C{1,2}))+(((2*A11*z1).*(C{1,1}))-(2*A11));
atm2=(((A11.*z2).*(z1.^2)).*(C{1,2}))+(((((A11-(Nu*A11)).*z3).*z1).*(al)));
atm3=((D11*z1.^2).*C{1,2})+((D11*z1).*C{1,1})-(D11+(A55*z1.^2));
atm4=((A55*z1.^2).*(al));
atm5=((((2*A55*z1)+((2*A11*Ug2).*z1)+((A11*z2.^2).*z1)+(2*Nu*A11*Ug3)).*C{1,2})+...
((2*A55)+(2*A11*Ug2)+((2*A11*Ug1).*z1)+(A11*z3.^2)-(((A11*z4).*z3).*z1).*(al)));
atm6=(((2*A55*z1).*C{1,1})+(2*A55));
atm7=((((2*Nu*A11)-((2*A11*z4).*z1)).*C{1,1})-(2*Nu*A11*z4));
eq1 = (atm*U)+(atm2*W) == 0;
eq2 = (atm3*PHI)-(atm4*W) == 0;
eq3 = (atm5*W)+(atm6*PHI)-(atm7*U) == 0;
vars = [U;W;PHI];
[Omega,b] = equationsToMatrix([eq1,eq2,eq3],vars);
P = [100,500,1000,5000,10000];
for i = 1:numel(P)
b(7) = P(i);
sol(i,:) = double(Omega\b);
end
sol
Torsten
el 8 de Jun. de 2023
You must compare the complete solutions for JabejayiU, KhizW and TaghirzaviyePHI for iteration step i and iteration step i+1. What you do is to compare element i+1 with element i of the arrays where i is the iteration step. This doesn't make sense, and MATLAB errors as soon as the iteration number exceeds the number of array elements (7).
mahdi
el 9 de Jun. de 2023
Torsten
el 9 de Jun. de 2023
You do not change the equations you solve within the loop. So you get the same solution 50 times. What should the iteration loop be good for ?
Torsten
el 9 de Jun. de 2023
If the solutions don't change, Ug1, Ug2, Ug3, z2 and z3 won't change, either.
mahdi
el 9 de Jun. de 2023
Torsten
el 9 de Jun. de 2023
I don't see where the new Ug1, Ug2, Ug3, z2 and z3 are used in eq1, eq2 and eq3 within the loop. If you want to use the new values for Ug1, Ug2, Ug3, z2 and z3 in eq1, eq2 and eq3, you have to recalculate atm, atm2,...,atm7.
mahdi
el 9 de Jun. de 2023
Your system now is nonlinear in U,W and PHI. The solution method used is no longer adequate. Don't iterate because there is no guarantee for convergence.
Set up your system as usual and use matlabFunction and fsolve instead of equationsToMatrix to solve it.
rng(1)
{}; % for example only
C{1,1} = rand(7);
C{1,2} = rand(7);
Nu = 0.285; A_11 = 64; A_55 = 37; D_11 = 2; w0c = 0.005; R = 0.5;
A11 = 6.4*10^4; A55 = 3.7*10^4; D11 = 2*10^3;
N = 7; a = 0; b = 0.5;
X1 = a+(b-a)*(1-cos(((1:N)-1)*pi/(N-1)))/2;
syms r
w0 = w0c*cos(pi*r/(2*R));
w0onX1 = double(subs(w0,r,X1));
A = C{1,1}*w0onX1.';
B = C{1,2}*w0onX1.';
B1 = C{1,2}*w0onX1.';
C_1 = cell2mat(C(1));
al = zeros(N);
al(2:N,1:N) = C_1(2:N,1:N);
bl = zeros(N);
bl(1:N-1,1:N) = C_1(1:N-1,1:N);
syms U [N,1]
syms W [N,1]
syms PHI [N,1]
z1 = X1;
z4 = B1.';
Ug1 = U.'*C{1,2}; Ug2 = U.'*C{1,1}; Ug3 = U.';
z2 = W.'*C{1,2}; z3 = W.'*C{1,1};
atm=((2*A11*z1.^2).*(C{1,2}))+(((2*A11*z1).*(C{1,1}))-(2*A11));
atm2=(((A11.*z2).*(z1.^2)).*(C{1,2}))+(((((A11-(Nu*A11)).*z3).*z1).*(al)));
atm3=((D11*z1.^2).*C{1,2})+((D11*z1).*C{1,1})-(D11+(A55*z1.^2));
atm4=((A55*z1.^2).*(al));
atm5=((((2*A55*z1)+((2*A11*Ug2).*z1)+((A11*z2.^2).*z1)+(2*Nu*A11*Ug3)).*C{1,2})+...
((2*A55)+(2*A11*Ug2)+((2*A11*Ug1).*z1)+(A11*z3.^2)+(((A11*z4).*z3).*z1).*(al)));
atm6=(((2*A55*z1).*C{1,1})+(2*A55));
atm7=((((2*Nu*A11)+((2*A11*z4).*z1)).*C{1,1})+(2*Nu*A11*z4));
eq1 = (atm*U)+(atm2*W) == 0;
eq2 = (atm3*PHI)-(atm4*W) == 0;
eq3 = (atm5*W)+(atm6*PHI)+(atm7*U) == 0;
eq1(7) = subs(eq1(7),lhs(eq1(7)),lhs(eq1(7))+sym('100'));
f = matlabFunction([lhs(eq1);lhs(eq2);lhs(eq3)],"Vars",{[U;W;PHI]})
[sol,fval] = fsolve(f,zeros(21,1))
U = sol(1:7)
W = sol(8:14)
PHI = sol(15:21)
Is this like the line b(7) = -100; ?
Yes.
And the code I gave you is complete - no modifications are necessary.
Of course I don't know whether "fsolve" returns a valid and reasonable solution. Nonlinear equations can have none or multiple solutions in contrast to linear systems.
Instead of
f = matlabFunction([lhs(eq1);lhs(eq2);lhs(eq3)],"Vars",{[U;W;PHI]})
[sol,fval] = fsolve(f,zeros(21,1))
you can also try
sol = vpasolve([eq1;eq2;eq3],[U;W;PHI])
to see if you get a different solution.
Respuestas (0)
Categorías
Más información sobre Assumptions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








