solve four variables 1111

3 views (last 30 days)
AAAAA
AAAAA on 11 Jan 2022
Edited: AAAAA on 15 Jan 2022
A = input('1,2;3,5');
B = input('8,-1;3,7');
C = input('2,6;8,4');
a1=A(1,1);
a2=A(1,2);
a3=A(2,1);
a4=A(2,2);
b1=B(1,1);
b2=B(1,2);
b3=B(2,1);
b4=B(2,2);
c1=C(1,1);
c2=C(1,2);
c3=C(2,1);
c4=C(2,2);
function fun=f(x)
fun(x)=[a1*x(1)+a2*x(3)+x(1)*b1+x(2)*b3-c1;
a1*x(2)+a2*x(4)+x(1)*b2+x(2)*b4-c2;
a3*x(1)+a4*x(3)+x(3)*b1+x(4)*b3-c3;
a3*x(2)+a4*x(4)+x(3)*b2+x(4)*b4-c4];
x=fsolve(f,[0;0]);
end

Answers (1)

Torsten
Torsten on 12 Jan 2022
Edited: Torsten on 12 Jan 2022
function main
A = input('1,2;3,5');
B = input('8,-1;3,7');
C = input('2,6;8,4');
a1=A(1,1);
a2=A(1,2);
a3=A(2,1);
a4=A(2,2);
b1=B(1,1);
b2=B(1,2);
b3=B(2,1);
b4=B(2,2);
c1=C(1,1);
c2=C(1,2);
c3=C(2,1);
c4=C(2,2);
x=fsolve(@(x)f(x,a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4),[0;0;0;0]);
end
function fun = f(x,a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4)
fun=[a1*x(1)+a2*x(3)+x(1)*b1+x(2)*b3-c1;
a1*x(2)+a2*x(4)+x(1)*b2+x(2)*b4-c2;
a3*x(1)+a4*x(3)+x(3)*b1+x(4)*b3-c3;
a3*x(2)+a4*x(4)+x(3)*b2+x(4)*b4-c4];
end
You solve a linear system of equations in x(1) - x(4).
fsolve is designed for nonlinear systems of equations.
Use linsolve instead.
  1 Comment
AAAAA
AAAAA on 15 Jan 2022
It makes sense! thank you very much

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!