フィルターのクリア

Piecewise function, ranges are variable

1 回表示 (過去 30 日間)
Franziska
Franziska 2019 年 8 月 6 日
コメント済み: Franziska 2019 年 8 月 6 日
Hi everyone
I want to plot this piecewise function:
a function in terms of ϵ, but where I can compare for different values of S. S is not only in some of the functions, but also defines the ranges of ϵ for which the function holds.
I tried to plot this: (but it didn't work).
function [y] = pwlaborsupply0(EPS, Beta, S)
if EPS<-(1+4*Beta)*S
y= 1 + (1/(1+4*Beta))*EPS;
elseif -(1+4*Beta)*S < EPS & EPS <= 4*Beta*S
y= 1+ (S+2*EPS)/(1+8*Beta);
elseif 4*Beta*S< EPS & EPS <=(1+4*Beta)*S
y=1+S;
else
y= 1 + (1/(1+4*Beta))*EPS;
end
% and then:
EPS=linspace(-0.5,0.5);
L0=pwlaborsupply0(EPS, 0.1,0.25);
plot(EPS, L0)
When I plot every part of the function separatly for a specific combinatin of β and S, (, ) it works: (but I calculated the ranges of ϵ manually, and I want to compare the result for different S, without going through this every time..)
Beta=0.1;
S=0.25;
EPS1=linspace(-0.5,-0.35);
EPS2=linspace(-0.35, 0.1);
EPS3=linspace(0.1, 0.35);
EPS4=linspace(0.35,0.5);
L01 = 1 + (1/(1+4*Beta))*EPS1;
L02 = 1+ (S+2*EPS2)/(1+8*Beta);
L03 = ones(size(EPS3))*(1+S);
L04 = 1 + (1/(1+4*Beta))*EPS4;
plot(EPS1,L01,EPS2,L02,EPS3,L03,EPS4,L04)
Any ideas how I can solve this, or where the problem in my definition of the function is?

採用された回答

Torsten
Torsten 2019 年 8 月 6 日
編集済み: Torsten 2019 年 8 月 6 日
EPS = linspace(-0.5,0.5);
L0 = arrayfun(@(C)pwlaborsupply0(C, 0.1,0.25),EPS);
plot(EPS,L0)
  1 件のコメント
Franziska
Franziska 2019 年 8 月 6 日
Works perfectly, thanks!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by