MATLAB無名関数の適用4



Application Matlab Anonymous Function 4



Sometimes it is necessary to derive some expressions, and perform operations such as evaluation, integration or extreme value on the obtained expressions. If the expression is not very complicated, it can be derived manually. But in many cases, manual derivation is very cumbersome or even impossible. At this time, it is necessary to use a computer to derive. After the expression is obtained, it is transformed into an anonymous function to facilitate subsequent follow-up

例1 [0,1]で次の関数の3階導関数のグラフを見つけます。
1

この例で手動計算を使用する場合は、より面倒です。シンボリック演算を使用して3次導関数の分析式を取得し、それを無名関数に変換すると、より便利です。
コードは次のとおりです



syms x f=(x+tan(x))^(sin(x)) c=diff(f,3) f3=eval(['@(x)' vectorize(c)]) x=linspace(0,1,100) plot(x,f3(x),'r','linewidth',2) title('y=(x+tan(x))^(sin(x)) third-order derivative image') xlabel('x')ylabel('y')

結果のグラフを図に示します。
画像
eval関数の機能は、文字列をmatlab実行可能ステートメントに変換することです。
vectorize関数の機能は、スカラーを受け入れる関数(より正確には呼び出し可能なオブジェクト)をベクトルを受け入れる関数に変換することです。