fplot differentiated symbolic equation

3 ビュー (過去 30 日間)
robert hyde
robert hyde 2017 年 11 月 8 日
回答済み: Omer Ali 2017 年 11 月 12 日
Hello there!
I'm trying to use the fplot function to plot an equation that I defined previously. However I think because I used syms and the diff() function to create the variable I am trying to plot, it is messing up the fplot function. My output is one graph which I already got to plot and an orange error message saying: '''The following error was reported evaluating the function in FunctionLine update: sym output type is not supported. Set 'UniformOutput' to false.'''
Any ideas for how to solve this? All other threads talk about arrayfun or something unrelated, if not, no worries, but thanks!
  1 件のコメント
robert hyde
robert hyde 2017 年 11 月 8 日
編集済み: robert hyde 2017 年 11 月 8 日
Here is my code (the error is in plotting Vg):

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

採用された回答

Star Strider
Star Strider 2017 年 11 月 8 日
I would calculate the derivative and create the anonymous function for ‘Vg’ with:
Vg = matlabFunction(diff(Mg,t), 'Vars',{t});
With that change, it runs without error, although the plot generates a long ‘Warning’ message.
  2 件のコメント
robert hyde
robert hyde 2017 年 11 月 8 日
this worked perfectly and fast, thanks! MVP isn't just a label
Star Strider
Star Strider 2017 年 11 月 8 日
As always, my pleasure!
Thank you very much for your compliment!

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

その他の回答 (2 件)

Karan Gill
Karan Gill 2017 年 11 月 8 日
You made a simple mistake. You used anonymous functions instead of symbolic functions. Declare a symbolic function using
syms Va(t)
Va(t) = t^2;
and plot it with fplot
fplot(Va)
See the second example in fplot doc: https://www.mathworks.com/help/symbolic/fplot.html
Comment if you have issues. If it works, please accept this answer.
  1 件のコメント
robert hyde
robert hyde 2017 年 11 月 8 日
This also worked and is a lot simpler to read, so I will use this as I am marked on how my code looks rather than it's run time, thank you very much!

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


Omer Ali
Omer Ali 2017 年 11 月 12 日
Thanks for asking this Rob! :)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by