Plotting Linear Inequality AND triangles

3 views (last 30 days)
TERRY DEGLOW
TERRY DEGLOW on 7 Aug 2011
I appreciate that this is relatively trivial, but I would like to use Matlab to help my nephew visualize high school algebra/trig functions.
First, How is a linear inequality plotted in matlab, complete with shading of the included region?
Second, given the usual imputs like side, angle side ..., how is the solution [if one exists] plotted in Matlab.
Thanks in advance

Answers (1)

Paulo Silva
Paulo Silva on 7 Aug 2011
Regarding the inequalities questions here's one example
t=-10:0.01:10; %values on x axes
f=t.^2-2; %values on y axes, put your function here
mif=1;maf=2; %select minimum and maximum value (y axes)
cla
axis([-10 10 -10 10])
hold on
line(xlim,[mif mif],'LineStyle','--','Color','k')
line(xlim,[maf maf],'LineStyle','--','Color','g')
idx=f>mif & f<maf; %select the index values of f that satisfy the conditions
plot(t,f) %plot the function
fill(t(idx),f(idx),'r') %fill the area that's inside the conditions
legend('maximum','minimum','function','area')
Regarding the triangles, maybe this
s1=2;s2=3;s3=2; %each side length
a1=40; %one angle in degrees
if all([s1+s2>s3,s3+s2>s1,s1+s3>s2])
cla;axis([-4 4 -4 4]);hold on
line([0 s1],[0 0])
line([0 s2*cosd(a1)],[0 s2*sind(a1)])
line([s2*cosd(a1) s1],[s2*sind(a1) 0])
grid on
else
disp('the lengths don''t make a triangle')
end

Categories

Find more on Line Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!