Plotting simple functions bounded by inequalities
显示 更早的评论
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
回答(1 个)
KSSV
2022-11-7
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 个评论
Emilia Miller
2022-11-7
m=-(0.7-0.3)/(10-(-10));
j=linspace(-30,30,100);
alpha_variable = m*j+0.5 ;
alpha_variable(j<-10) = 0.7 ;
alpha_variable(j>10) = 0.3 ;
plot(j,alpha_variable)
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.)
Emilia Miller
2022-11-7
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


