solve four variables 1111

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

回答 (1 件)

Torsten
Torsten 2022 年 1 月 12 日
編集済み: Torsten 2022 年 1 月 12 日

1 投票

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 件のコメント

AAAAA
AAAAA 2022 年 1 月 15 日
It makes sense! thank you very much

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 1 月 11 日

編集済み:

2022 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by