Piecewise function, ranges are variable
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone
I want to plot this piecewise function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232925/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232926/image.png)
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..)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232927/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232928/image.png)
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 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!