Clear Filters
Clear Filters

Piecewise function, ranges are variable

1 view (last 30 days)
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?

Accepted Answer

Torsten
Torsten on 6 Aug 2019
Edited: Torsten on 6 Aug 2019
EPS = linspace(-0.5,0.5);
L0 = arrayfun(@(C)pwlaborsupply0(C, 0.1,0.25),EPS);
plot(EPS,L0)

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!