Substitute multiple values to array of expressions

I have the following code that forms 4 symbolic equations (xs1, xs2, xs3, xs4) using 4 symbolic variables (x1, x2, x3, x4). Problem is, I cannot substitute numeric values into the equations.
A=[9,1,1,1;1,8,1,1;1,1,7,1;1,1,1,6];
B=[75;54;43;34];
x=sym('x',[1 4]);
xs=sym('xs',[1 4]);
xs(1:4)=0;
for i=1:4
for j=1:4
if(j==i)
continue
end
xs(i)=xs(i)-x(j);
end
xs(i)=1/A(i,i)*(B(i)+xs(i));
end
What I tried,
x(1:4)=0;
subs(xs);
%another one
subs(xs(1),{x(1),x(2),x(3),x(4)},{[0,0,0,0]})
None worked. How do I do this?

 採用された回答

Star Strider
Star Strider 2019 年 5 月 19 日

0 投票

The ‘x’ values are not ‘x1’, ‘x2’, ..., but ‘x(1)’, ‘x(2)’, ...
Try this instead:
q = subs(xs(1),{x(1),x(2),x(3),x(4)},{[0,0,0,0]});
(Asssign it to whatever variable name you want.)

2 件のコメント

Yavuz Selim Tozlu
Yavuz Selim Tozlu 2019 年 5 月 19 日
I'm pretty sure I've tried this before, and it didn't seem to work back then. Now it works just fine. I was probably doing something wrong. Thanks!
Star Strider
Star Strider 2019 年 5 月 19 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by