Trying to plot function f(x) = x + 1 / x^2 - 1. fplot and plot giving 2 different graphs.

4 views (last 30 days)
I'm trying to plot the function:
f(x) = x + (1 /x^2-1)
for -4 <= x <= 4 by dividing the domain of x's into three parts, -4 to the left asymptote -1, asymptote to asymptote (-1, 1), and right asymptote 1 to 4.
When I do the fplot command:
syms x
fplot(y, ([-4, -1]))
hold on
fplot(y, ([-1, 1]))
hold on
fplot(y, ([1, 4]))
It works like I'm wanting it to, but I can't seem to get it to work by specifying x or using the plot command and I wasn't sure what I was doing wrong.

Accepted Answer

David Hill
David Hill on 14 Sep 2020
x=-4:.001:4;
f=x + 1./(x.^2-1);
plot(x,f);

More Answers (1)

Rupam Nath
Rupam Nath on 9 Feb 2024
if true x<1
% code
end x>1

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!