# i'd like to ask is there any function to find asymptotes of an equation y = f(x) that satisfies x = x(t) and y = y(t). I'm new to matlab.

7 views (last 30 days)
Nhat Huy on 25 Nov 2023
Commented: John D'Errico on 1 Dec 2023
syms t
x = (t+1)./(t-1);
y = (t^2+2)./(t^2-t);
% Find horizontal asymptotes
syms x0
tx = solve(x == x0, t);
num_ha = 0;
sh = [];
for id = 1:length(tx)
yx = subs(y, t, tx(id));
for s = 0:1
infi = (-1)^s*inf;
ya = limit(yx, x0, infi);
if isfinite(ya)
fprintf('Tiem can ngang la: y = %f\n', ya)
num_ha = num_ha + 1;
end
end
end
fprintf('Do thi ham f(x) co %d tiem can ngang\n------------------\n', num_ha)
Do thi ham f(x) co 0 tiem can ngang ------------------
% Find slant asymptotes
num_sa = 0;
ss = [];
for id = 1:length(tx)
yx = subs(y, t, tx(id));
for s = 0:1
infi = (-1)^s*inf;
a = limit(yx/x0, x0, infi);
b = limit(yx - a*x0, x0, infi);
c = [a b];
if isfinite(a) && isfinite(b)
new = 1;
for k = 1:size(ss, 1)
if all(c == ss(k, :))
new = 0;
break
end
end
if new
ss = [ss; c];
fprintf('Tiem can xien la: y = x * %f + %f\n', a, b)
num_sa = num_sa + 1;
end
end
end
end
Tiem can xien la: y = x * 1.500000 + -2.500000
fprintf('Do thi ham f(x) co %d tiem can xien\n-------------------\n', num_sa)
Do thi ham f(x) co 1 tiem can xien -------------------
% Find vertical asymptotes
syms y0
ty = solve(y == y0, t);
num_va = 0;
sv = [];
for s = 0:1
infi = (-1)^s * inf;
ti = subs(ty, y0, infi);
for id = 1:length(ti)
t0 = ti(id);
if ~isreal(t0)
continue
end
xa = limit(x, t, t0);
if isfinite(xa)
new = 1;
for k = 1:size(sv, 1)
if xa == sv(k)
new = 0;
break
end
end
if new
sv = [sv xa];
fprintf('Tiem can dung la: x = %f\n', xa)
num_va = num_va + 1;
end
end
end
end
fprintf('Do thi ham f(x) co %d tiem can dung\n-------------------\n', num_va)
Do thi ham f(x) co 0 tiem can dung -------------------
figure
hold on
fplot(x, y)
xlabel('Ox')
ylabel('Oy')
grid on
John D'Errico on 1 Dec 2023
Edited: John D'Errico on 1 Dec 2023
Please don't keep on reposting your question. I closed it as a pure duplicate.
As I said in my answer, your question is not even a question about MATLAB. Until you know how to approach a problem, you cannot write code to solve it. There is no tool in MATLAB to solve your problem.

John D'Errico on 25 Nov 2023
Edited: John D'Errico on 25 Nov 2023
Its an interesting question of mathematics, maybe not really a question about MATLAB in my eyes, because until you know how to solve a problem using mathematics, you cannot hope to write code.
Is there any function? No. Sorry, but I don't see any way to do so, since x and y can be literally anything. And since they could be arbitraily complicated, messy functional forms, it might even be possible to find some pair of functions where we cannot prove that an asymptote exists or not.
You have made an interesting attempt at a solution, where you look for points where x or y approach infinity, but I could counter with examples where x or y go to infinity at infinitely many points.

Walter Roberson on 1 Dec 2023
syms t;
x_t = (t+1)./(t-1);
y_t = (t^2 + 2)./(t^2 - t);
limit(y_t, t, -inf)
ans =
1
limit(y_t, t, 0, 'left')
ans =
limit(y_t, t, 0, 'right')
ans =
limit(y_t, t, 1, 'left')
ans =
limit(y_t, t, 1, 'right')
ans =
limit(y_t, t, inf)
ans =
1
John D'Errico on 1 Dec 2023
But this does not answer the question of how to identify a possibly linear asymptote. Or what to do if you cannot easily identify poles of the functions for a completely general problem.

### Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!