I have to solve a system of equations in the form Ax=b+F, where A is a known 8x8 matrix. Also the term F is all known.
The problem is that I have unknowns both in the term x and b (4 in x and 4 in b, the other terms are given by boundary conditions).
How can I set the problem on matlab?
Thanks.

 Respuesta aceptada

Torsten
Torsten el 28 de Feb. de 2019

0 votos

function main
x0=zeros(8,1);
sol=fminsearch(@(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8)),x0)
sol=fminsearch(@(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8)),sol)
sol=fminsearch(@(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8)),sol)
sol=fminsearch(@(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8)),sol)
res=fun(sol(1),sol(2),sol(3),sol(4),sol(5),sol(6),sol(7),sol(8))
end
function res = fun(a1,a2,a3,a4,R1,R2,R3,R4)
l1=50;
l2=50;
l3=50;
Fc1=30;
Fc2=50;
Fc3=100;
a=25;
b=25;
c=25;
d=25;
e=25;
f=25;
v1=0;
v2=0;
v3=0;
v4=0;
m1=0;
m2=0;
m3=0;
m4=0;
A=[12/l1^2, 6/l1^2, -12/l1^3, 6/l1^2, 0, 0, 0, 0;...
6/l1^2, 4/l1^2, -6/l1^2, 4/l1^2, 0, 0, 0, 0; ...
-12/l1^3, -6/l1^2, 12/l1^3+12/l2^3, -6/l1^2+6/l2^2, -12/l2^3, 6/l2^2, 0, 0; ...
6/l1^2, 2/l1 -6/l1^2+6/l2^2, 4/l1+4/l2, -6/l2^2, 4/l2, 0, 0; ...
0, 0, -12/l2^3, -6/l2^2, 12/l2^3+12/l3^3, -6/l2^2+6/l3^2, -12/l3^3, 6/l3^2; ...
0, 0, 6/l2^2, 2/l2, -6/l2^2+6/l3^2, 4/l2+4/l3, -6/l3^2, 4/l3; ...
0, 0, 0, 0, -12/l3^3, -6/l3^2, 12/l3^3, -6/l3^2; ...
0, 0, 0, 0, 6/l3^2, 2/l3, -6/l3^2, 4/l3];
x=[v1, a1, v2, a2, v3, a3, v4, a4]';
s=[R1, m1, R2, m2, R3, m3, R4, m4]';
F=[(l1+2*a^3-3*l1*a^2)*Fc1/l1^3, (a^3+l1^2*a-2*l1*a)*Fc1/l1^3, ...
(2*a^3-3*l1*a^2)*Fc1/l1^2+(l2+2*c^3-3*l2*c^2)*Fc2/l2^3, (a^3-l1*a^2)*Fc1/l1^2+(c^3+l2^2*c-2*l2*c)*Fc2/l2^2, ...
(2*c^3-3*l2*c^2)*Fc2/l2^2+(l3+2*e^3-3*l3*e)*Fc3/l3^3, (c^3-l2*c^2)*Fc2/l2^2+(e^3+l3*e-2*l3*e)*Fc3/l3^2, ...
(2*e^3-3*l3*e^2)*Fc3/l3^3, (e^3-l3^2)*Fc3/l3^2]';
res=sum((A*x-s-F).^2);
end

Más respuestas (1)

Walter Roberson
Walter Roberson el 27 de Feb. de 2019

0 votos

A = sym('A',[8 8],'real');
x = sym('x',[8 1]);
b = sym('b',[8 1]);
F = sym('F',[8 1]);
sol = solve(A*x == b+F,[x(1:4);b(5:8)]); %choose appropriate variables to solve for
sol will be a struct with one field for each variable solved for.
The above is the general solution, at least under the assumption that F does not depend upon the other variables.
It is not a fast solution. If you were to put in your known numeric values then it would probably go more quickly.

2 comentarios

Lorenzo Stabile
Lorenzo Stabile el 28 de Feb. de 2019
Editada: Walter Roberson el 28 de Feb. de 2019
I tried to implement the code but it doesn't work, because of I'm not sure I really understood the solution you wrote me.
The values I have are:
A=[12/l1^2, 6/l1^2, -12/l1^3, 6/l1^2, 0, 0, 0, 0;...
6/l1^2, 4/l1^2, -6/l1^2, 4/l1^2, 0, 0, 0, 0; ...
-12/l1^3, -6/l1^2, 12/l1^3+12/l2^3, -6/l1^2+6/l2^2, -12/l2^3, 6/l2^2, 0, 0; ...
6/l1^2, 2/l1 -6/l1^2+6/l2^2, 4/l1+4/l2, -6/l2^2, 4/l2, 0, 0; ...
0, 0, -12/l2^3, -6/l2^2, 12/l2^3+12/l3^3, -6/l2^2+6/l3^2, -12/l3^3, 6/l3^2; ...
0, 0, 6/l2^2, 2/l2, -6/l2^2+6/l3^2, 4/l2+4/l3, -6/l3^2, 4/l3; ...
0, 0, 0, 0, -12/l3^3, -6/l3^2, 12/l3^3, -6/l3^2; ...
0, 0, 0, 0, 6/l3^2, 2/l3, -6/l3^2, 4/l3];
x=[v1, a1, v2, a2, v3, a3, v4, a4]';
s=[R1, m1, R2, m2, R3, m3, R4, m4]';
F=[(l1+2*a^3-3*l1*a^2)*Fc1/l1^3, (a^3+l1^2*a-2*l1*a)*Fc1/l1^3, ...
(2*a^3-3*l1*a^2)*Fc1/l1^2+(l2+2*c^3-3*l2*c^2)*Fc2/l2^3, (a^3-l1*a^2)*Fc1/l1^2+(c^3+l2^2*c-2*l2*c)*Fc2/l2^2, ...
(2*c^3-3*l2*c^2)*Fc2/l2^2+(l3+2*e^3-3*l3*e)*Fc3/l3^3, (c^3-l2*c^2)*Fc2/l2^2+(e^3+l3*e-2*l3*e)*Fc3/l3^2, ...
(2*e^3-3*l3*e^2)*Fc3/l3^3, (e^3-l3^2)*Fc3/l3^2]';
with
l1=l2=l3=50; Fc1=30; Fc2=50; Fc3=100; a=b=c=d=e=f=25;
v1=v2=v3=v4=0
and
m1=m2=m3=m4=0
.
The unknowns are a1, a2, a3, a4, R1, R2, R3, R4.
Walter Roberson
Walter Roberson el 28 de Feb. de 2019
Code attached. Solution is a small number of seconds once the Symbolic Toolbox has been initialized.

Iniciar sesión para comentar.

Preguntada:

el 27 de Feb. de 2019

Comentada:

el 28 de Feb. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by