Hi all,
I tried to plot a function \frac{1}{(x-1)^{2/3}}
but it can only plot the function from x=1 to the right. There should also be the plot from from x=0
to x=1
toward infinity.
This is the suppose to be function plot:
This is my code to plot with JULIA:
using Plots, LaTeXStrings, Plots.PlotMeasures # ignore any warnings
gr()
f(x) = 1/(x-1)^(2/3)
plot(f,-1,6; color=:blue, xlims=(-1,6), xtick=-1:1:6, yaxis=false,ylims=(-1,10),
framestyle=:zerolines, label=L"y = f(x) = \frac{1}{(x-1)^{2/3}}",
top_margin=10mm, legend=:topright)
I also try to use matplotlib by calling from C++ and it is the same,
// g++ main.cpp -o main -std=c++11 -I/usr/include/python3.9 -lpython3.9 -DWITHOUT_NUMPY
// g++ main.cpp -o main -std=c++11 -lpython3.9 -I/usr/include/python3.9 -I/usr/lib/python3.9/site-packages/numpy/core/include
#include "matplotlibcpp.h"
#include <cmath>
double division(double x, double y)
{
return x/y;
}
namespace plt = matplotlibcpp;
int main()
{
// Prepare data.
int n = 1000;
std::vector<double> x(n), y(n), z(n);
for(int i=0; i<n; ++i)
{
x.at(i) = i;
y.at(i) = pow(i-1,-division(2,3));
}
// Set the size of output image to 1200x780 pixels
plt::figure_size(1200, 780);
// Plot line from given x and y data. Color is selected automatically.
plt::plot(x, y);
// Plot a line whose name will show up as "x exp(-x)" in the legend.
plt::named_plot("1/(x-1)^(2/3)", x, y);
// Set x-axis to interval [0,10]
plt::xlim(0, 10);
// Add graph title
plt::title("1/(x-1)^(2/3)");
// Enable legend.
plt::legend();
plt::show();
// Save the image (file format is determined by the extension)
// plt::save("./basic.png");
}
and also with gnuplot:
// Compile it with:
// g++ -o main main.cpp -lboost_iostreams
#include <vector>
#include <cmath>
#include <utility>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
// Don't forget to put "\n" at the end of each line!
gp << "set xrange [-2:4]\nset yrange [0:5]\n";
// '-' means read from stdin. The send1d() function sends data to gnuplot's stdin.
gp << "f(x) = 1/(x-1)**(0.666667)\n";
gp << "plot f(x) title 'f(x) = 1/(x-1)^{2/3}'\n";
return 0;
}
It seems even matplotlib and gnuplot cannot plot the function from x=0
to x=1