I would like to know how to differentiate or derive a function handler based on user input. I tried using diff but that doesn't work.
f = @(x) input
end
that's how i expect to get an input polynomial function from the user who run the program. I'm really new to matlab and now struggling to find the solution. Thanks for your answer.

3 件のコメント

Ameer Hamza
Ameer Hamza 2018 年 5 月 6 日
Can you tell what type of input can the user give?
Timothy Wibisono
Timothy Wibisono 2018 年 5 月 6 日
i'm expecting the user to input a polynomial function, something like (5*x^3) or etc.
Ameer Hamza
Ameer Hamza 2018 年 5 月 6 日
Refer to my answer below.

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

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 6 日

0 投票

One solution is to use symbolic math toolbox
df = matlabFunction(diff(sym(f)));

4 件のコメント

Timothy Wibisono
Timothy Wibisono 2018 年 5 月 6 日
Thanks, that works, but what if I'd also like to find the second derivative, or the derivative of df that you provided?
And, can i also find the integration within certain limits of a function handler based on user input?
Ameer Hamza
Ameer Hamza 2018 年 5 月 6 日
For the second derivative, there are two ways.
1) Since you already have function handle for df, you can get its derivative similarly.
df2 = matlabFunction(diff(sym(df)));
2) Or you can directly find the second derivative in the first step if you don't need the first derivative
df2 = matlabFunction(diff(sym(f), 2));
As far as integration is concerned, you can use integral() to directly integrate function handle.
Timothy Wibisono
Timothy Wibisono 2018 年 5 月 6 日
thanks for your answer, it really helps.
Ameer Hamza
Ameer Hamza 2018 年 5 月 6 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Mathematics についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by