Plotting Linear Inequality AND triangles
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Paulo Silva
2011년 8월 7일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!