vector output of a symbolic vector
2 ビュー (過去 30 日間)
古いコメントを表示
syms s X Y Z
l1 = X*s - 1 == 3*X + Y + Z + 2/s
l2 =Y*s == - X - Y - 1/s^2
l3 =Z*s - 2 == X - Z - (s - 1)/s^2
[Xsol,Ysol,Zsol]=solve([l1,l2,l3],[X,Y,Z])
[Xsol,Ysol,Zsol]=partfrac([Xsol,Ysol,Zsol])
Too many output arguments."
Why?
0 件のコメント
回答 (3 件)
John D'Errico
2024 年 10 月 3 日
編集済み: John D'Errico
2024 年 10 月 3 日
syms s X Y Z
l1 = X*s - 1 == 3*X + Y + Z + 2/s
l2 =Y*s == - X - Y - 1/s^2
l3 =Z*s - 2 == X - Z - (s - 1)/s^2
[Xsol,Ysol,Zsol]=solve([l1,l2,l3],[X,Y,Z])
Up to this point, you have done nothing wrong. Xsol, Ysol, and Zsol are all validly defined expressions of x, y, and z.
Then you tried to use partfrac, as applied to a vector, composed of [xsol,ysol,zsol].
help partfrac
You could have applied partfrac to any one of them.
Xsolpf = partfrac(Xsol)
However, partfrac is not vectorized. And when you tried that as you did, it gave you an error. The point is, you could just have called partfrac three times. But not everything you write in MATLAB will be vectorized to work as you might hope it should work. Code is only code. As much as we wish it would do so, it cannot do more than it was written to do.
Could you have done like this?
XYZsol = partfrac([Xsol,Ysol,Zsol])
And then separated each of the three components into a separate result? Well, yes.
XYZsol(1)
XYZsol(2)
XYZsol(3)
1 件のコメント
John D'Errico
2024 年 10 月 3 日
Sorry. The Answers bug is again present. When I wrote this post, if displays nicely. But when saved, it fails to do so.
Vinay
2024 年 10 月 3 日
The issue stems from the “partfrac” function, which is configured to accept only a single output argument. This function specifically performs partial fraction decomposition on:
- A single symbolic expression, or
Xsol_partfrac = partfrac(Xsol);
Ysol_partfrac = partfrac(Ysol);
Zsol_partfrac = partfrac(Zsol);
- An array of symbolic expressions
result=partfrac([Xsol,Ysol,Zsol])
To resolve this issue, decompose each expression individually using the “partfrac” function or to pass the array of symbolic expression and store result in a single argument. This approach ensures proper handling of each term and prevents the multiple output argument error.
Kindly refer to the below documentation of “partfrac” for more details:
I hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Variables, Expressions, Functions, and Preferences についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!