Plotting simple functions bounded by inequalities

7 views (last 30 days)
Hi,
I am trying to plot the albedo-ice feedback for a simple function as seen in the picture below:
This is the code I have written so far (where Ts_ is the temperature I have from an ODE previously solved where I had assumed alpha was constant):
m=-0.08;
j=linspace(min(Ts_),max(Ts_),100);
if j<-10
alpha_variable=0.7
if j>10
alpha_variable=0.3
else
alpha_variable=m*j;
end
end
figure(3);
plot(j,alpha_variable)
I am only plotting it to see that I have the correct relationship before moving on but for some reason the plot is just coming up as the linear equation at the bottom (i.e. alpha_variable=m*j).
I have tried changing j for Ts_ in my if statements, but this isn't working either.
Any help is much appreciated! :)
Thanks,
Emilia

Answers (1)

KSSV
KSSV on 7 Nov 2022
m=-0.08;
j=linspace(min(Ts_),max(Ts_),100);
alpha_variable = m*j ;
alpha_variable(j<-10) = 0.7 ;
alpha_variable(j>10) = 0.3 ;
plot(j,alpha_variable)
  4 Comments
Steven Lord
Steven Lord on 7 Nov 2022
1) The region where your function is not constant is between -10 and +10, but you're plotting this function over the interval (roughly) -275 to 20 or 30. If you changed the axes limits to exclude the region between -300 and say -20 your function will look a little different.
m=-0.08;
j=linspace(-20, 20,100);
alpha_variable = m*j ;
alpha_variable(j<-10) = 0.7 ;
alpha_variable(j>10) = 0.3 ;
plot(j,alpha_variable)
2) You need to adjust the equation of the line you're using to connect the regions less than -10 (which has a constant value of 0.7) and the region greater than 10 (which has a constant value of 0.3.)

Sign in to comment.

Categories

Find more on Graph and Network Algorithms 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!