Piecewise function, ranges are variable
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!