vector output of a symbolic vector
1 次查看(过去 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!