What does the value s do in my code??
Show older comments
clear
clf
f=@(x)((x.^2)-1)./((x.^2)-4);
xa=-10; xb=-2; s=1; ya=-5; yb=5;
xv=linspace(xa, -s); xh=linspace(s ,xb);
plot(xv,f(xv),'blue',xh,f(xh),'blue','linewidth',2)
axis equal, axis([xa xb ya yb]), grid on,hold on
xlabel('x'), ylabel('y'), title('((x.^2)-1)./((x.^2)-4)')
f=@(x)((x.^2)-1)./((x.^2)-4);
xa=-2; xb=2; s=0; ya=-5; yb=5;
xv=linspace(xa,-s); xh=linspace(s,xb);
plot(xv,f(xv),'blue',xh,f(xh),'blue','linewidth',2)
axis equal, axis([xa xb ya yb]), grid on,
f=@(x)((x.^2)-1)./((x.^2)-4);
xa=2; xb=10; s=1; ya=-5; yb=5;
xv=linspace(xa,-s); xh=linspace(s,xb);
%xv=linspace(xa,xb);
plot(xv,f(xv),'blue',xh,f(xh),'blue','linewidth',2)
axis equal, axis([-5 5 ya yb]), grid on,
Can anyone explain what s does in my equation. When I tried making the graph from the helpful input from my earlier question (thank you everyone) the problem was that the graph had two blue lines where the asymptotes should be. I splitted the x-values in 3 parts and made s=1 instead of s=0 for the two graphs above y=1 and then my graph worked the way it should. This however has not made me any wiser to what s means and does...Can anyone explain?
1 Comment
Britney
on 16 Oct 2014
Accepted Answer
More Answers (2)
Britney
on 16 Oct 2014
Matt Tearle
on 16 Oct 2014
This code is... a bit muddled. At the end of the day, the s is not really necessary. The problem you were having before with the line across the asymptotes is that MATLAB simply calculates the values in the x vector and joins the points up, so on one side of the asymptote (x = -2.mumble) y is 10^23 (or whatever) and the next x value on the other side (x = -1.9mumble) y = -10^17. The simplest way to fix that is just split the x vector into three pieces ([-5,-2], [-2,2], [2,5]).
Your code kinda does that in a roundabout way, but you can make it much cleaner by just making three x vectors and plotting the corresponding y values for each:
f=@(x)((x.^2)-1)./((x.^2)-4);
xa=-5; xb=-2;
x1=linspace(xa,xb);
x2=linspace(xb,-xb);
x3=linspace(-xb,-xa);
plot(x1,f(x1),'blue',x2,f(x2),'blue',x3,f(x3),'blue','linewidth',2)
Regarding your second question, the input to title is just a string, so you can put anything you want there:
title('(x^2-1)/(x^2-4)')
MATLAB will interpret the carats as exponent markup, which is nice. But you can also go completely nuts if you know LaTeX:
title('$$\frac{x^2-1}{x^2-4}$$','Interpreter','latex')
1 Comment
Categories
Find more on Graphics Object Properties 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!