Plotting Linear Inequality AND triangles
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Paulo Silva
il 7 Ago 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!