plotting a symbolic array of functions

9 ビュー (過去 30 日間)
Cyrus Ghorbani
Cyrus Ghorbani 2022 年 3 月 10 日
コメント済み: Star Strider 2022 年 3 月 10 日
I have a symbolic array in the form of [f(theta,phi) g(theta,phi) 0] where theta and phi are symbolic variables. The indicies of the array represent (x,y,z) coordinates which vary as functions of phi and theta. I dont think i can use fplot or ezplot or similar functions to plot this, so I'm wondering what is the best approach? Im looking for something like a scatter plot.

採用された回答

Star Strider
Star Strider 2022 年 3 月 10 日
Use the matlabFunction function to convert the symbolic functions into functions that can be used numerically. Then, if ‘theta’ and ‘phi’ are vectors, use ndgrid or meshgrid to create the matrices from them that are necessary to evaluate both of them together.
  2 件のコメント
Cyrus Ghorbani
Cyrus Ghorbani 2022 年 3 月 10 日
Thank you, i managed to get it to work using those tools! This is the resulting donut:
Is it totally necessary to do this numerically? this plot had 2500 sets of (x,y,z) data points and was pretty slow and i'm wondering if there is a way to keep it symbolic.
Star Strider
Star Strider 2022 年 3 月 10 日
As always, my pleasure!
The Symbolic Math Toolbox is significantly slower than the numerical approach, since it’s best use is to do one-off derivations and such, not anything repeated. That’s the reason I suggested using matlabFunction and then doing the rest of the calculations numerically, preferably using vectorised code.
I don’t know how you coded the result you got. I suggested using ndgrid or meshgrid to create matrices from the vectors, then using those matrices as the function arguments. That would likely be reasonably fast. If you used loops, you can get about a 20% increase in speed by preallocating the result matrices. That involves creating the result matrices before the loop as matrices of zeros, and then just indexing into them in the loop.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by