vector output of a symbolic vector
2 views (last 30 days)
Show older comments
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 Comments
Answers (3)
John D'Errico
on 3 Oct 2024
Edited: John D'Errico
on 3 Oct 2024
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 Comment
John D'Errico
on 3 Oct 2024
Sorry. The Answers bug is again present. When I wrote this post, if displays nicely. But when saved, it fails to do so.
Vinay
on 3 Oct 2024
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 Comments
See Also
Categories
Find more on Symbolic Variables, Expressions, Functions, and Preferences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!