How to find the maximum and minimum values of a piecewise function?

8 ビュー (過去 30 日間)
Edgar Dominguez Ugalde
Edgar Dominguez Ugalde 2017 年 12 月 6 日
コメント済み: Shivam Kaushik 2019 年 11 月 7 日
I have defined the following piecewise function:
s = piecewise(0<theta<50*pi/180, 0, 50*pi/180<theta<100*pi/180, curv_arm, 100*pi/180<theta<2*pi, curv_par);
where `curv_arm` and `curv_par` are functions that I wrote at the beginning. And I used the command fplot to display the plot of this function. Now I want to obtain the maximum and the minimum value of this function in the interval [0,pi] but I'm getting the following error:
"s" was previously used as a variable,
conflicting with its use here as the name of a function
or command
I'm trying with the following line:
[x,fval] = fminbnd(@s,0,pi)
The plot is the following:
  1 件のコメント
Shivam Kaushik
Shivam Kaushik 2019 年 11 月 7 日
sigmoid_exact = @(x)(((-4<x) & (x<4))*1/(1+exp(-x)));
sigmoid_approx = @(x) (((0<x) & (x<4))*(1-0.5*((1-0.25*x)^(2)))+((-4<x) & (x<0))*(0.5*((1+0.25*x)^(2)))+(x>4)*1+(x<-4)*0);
error = @(x) (sigmoid_exact-sigmoid_approx) ;
how to obtain plot
piecewise non linear approximation of sigmoid function
i have to minimze error

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

採用された回答

Star Strider
Star Strider 2017 年 12 月 6 日
I’m not quite sure what you want to do. This will get you started:
curv_arm = 3;
curv_par = 5;
s = @(theta, curv_arm, curv_par) [0*((0<theta) & (theta<50*pi)) + curv_arm.*((50*pi/180<theta) & (theta<100*pi/180)) + curv_par.*((100*pi/180<theta) & (theta<2*pi))];
[x,fval] = fminbnd(@(theta)s(theta, curv_arm, curv_par),0,pi)
You cannot use a symbolic expression with fminbnd, and ‘matlabFunction’ will not create a function from your piecewise function. You can easily create your own function for numeric applications using essentially the same code, and ‘logical indexing’, as I did here.
Make any necessary changes to get the result you want.
  6 件のコメント
Edgar Dominguez Ugalde
Edgar Dominguez Ugalde 2017 年 12 月 6 日
OK, I'll try. I really appreciate your help.
Star Strider
Star Strider 2017 年 12 月 6 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by