Find the derivative of a piecewise function and plot the result

7 ビュー (過去 30 日間)
Edgar Dominguez Ugalde
Edgar Dominguez Ugalde 2017 年 12 月 6 日
コメント済み: Star Strider 2017 年 12 月 7 日
Hi, I have the following code which includes a piecewise function "s" of theta and I would like to differentiate this function with respect to theta and plot the result after.
L = 2.5;
betha1 = 50*pi/180;
betha2 = 260*pi/180;
curv_arm = @(theta) L/2*(1-cos((pi*(theta-betha1))/betha1));
curv_par = @(theta) L*(1-(theta-(100*pi/180))/(betha2)+((1)/(2*pi))*(sin(2*pi*(theta-(100*pi/180))/(betha2))));
syms theta
s = @(theta) [0*((0<theta) & (theta<50*pi)) + curv_arm(theta).*((50*pi/180<theta) & (theta<100*pi/180)) +
curv_par(theta).*((100*pi/180<theta) & (theta<2*pi))];
fplot(s, [0,6], 'b')
I have managed to plot the current function but I can't differentiate with the command diff for some reason

採用された回答

Star Strider
Star Strider 2017 年 12 月 6 日
The Symbolic Math Toolbox diff function will not differentiate it because of the discontinuities, either using my function or your original symbolic function for ‘s’. (The derivative does not exist at the discontinuities.)
The best you can do is to evaluate it numerically over a suitably fine vector for ‘theta’ (use the linspace function) and then use the gradient function to calculate the numerical derivative.
Then you can plot both the function and its numerical derivative as functions of ‘theta’.
  10 件のコメント
Edgar Dominguez Ugalde
Edgar Dominguez Ugalde 2017 年 12 月 7 日

Now I get it! Thanks man, you da real MVP

Star Strider
Star Strider 2017 年 12 月 7 日
Thank you!
(I removed the ‘spam’ warning.)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by