TransWikia.com

how to plot the graph of octagonal fuzzy number in latex?

TeX - LaTeX Asked on June 29, 2021

if the membership function is as follows, then how to draw the graph of it in Latex?enter image description here

One Answer

Just use pgfplots (I added some parameters you can play around with):

documentclass{standalone}
usepackage{pgfplots}
usetikzlibrary{math}
begin{document}
    begin{tikzpicture}
        tikzmath{
            real k;
            real a0;
            real a1;
            real a2;
            real a3;
            real a4;
            real a5;
            real a6;
            real a7;
            real a8;
            k=3.0;
            a0=-5.0;
            a1= -3.0;
            a2= 2.0;
            a3= 4.0;
            a4= 5.0;
            a5= 9.0;
            a6= 10.0;
            a7= 11.0;
            a8= 12.0;
            a9=14.0;
        };
    begin{axis} [grid=major,legend style={overlay},every axis plot post/.append style={mark=none}]
        addplot [domain = a0:a1,color=blue]
        {0};
        addplot [domain = a1:a2,color=blue]
        {k*(x-a1)/(a2-a1)};
        addplot [domain = a2:a3,color=blue]
        {k};
        addplot [domain = a3:a4,color=blue]
        {k + (1-k)*(x-a3)/(a4-a3)};
        addplot [domain = a4:a5,color=blue]
        {1};
        addplot [domain = a5:a6,color=blue]
        {k + (1-k)*(a6-x)/(a6-a5)};
        addplot [domain = a6:a7,color=blue]
        {k};
        addplot [domain = a7:a8,color=blue]
        {k*(a8-x)/(a8-a7)};
        addplot [domain = a8:a9,color=blue]
        {0};
        
    end{axis}
end{tikzpicture}
end{document}

Adding the specific x-coordinates can be done by adapting the so-called ticks:

documentclass{standalone}
usepackage{pgfplots}
usetikzlibrary{math}
begin{document}
    begin{tikzpicture}
        tikzmath{
            real k;
            real a0;
            real a1;
            real a2;
            real a3;
            real a4;
            real a5;
            real a6;
            real a7;
            real a8;
            k=3.0;
            a0=-5.0;
            a1= -3.0;
            a2= 2.0;
            a3= 4.0;
            a4= 6.0;
            a5= 9.0;
            a6= 11.0;
            a7= 13.0;
            a8= 15.0;
            a9= 17.0;
        };
    begin{axis} [grid=major,legend style={overlay},every axis plot post/.append style={mark=None},xtick={a1,a2,a3,a4,a5,a6,a7,a8},
            xticklabels={$a_1$,$a_2$,$a_3$,$a_4$,$a_5$,$a_6$,$a_7$,$a_8$}]
        addplot [domain = a0:a1,samples=2,color=blue]
        {0};
        addplot [domain = a1:a2,samples=2,color=blue]
        {k*(x-a1)/(a2-a1)};
        addplot [domain = a2:a3,samples=2,color=blue]
        {k};
        addplot [domain = a3:a4,samples=2,color=blue]
        {k + (1-k)*(x-a3)/(a4-a3)};
        addplot [domain = a4:a5,samples=2,color=blue]
        {1};
        addplot [domain = a5:a6,samples=2,color=blue]
        {k + (1-k)*(a6-x)/(a6-a5)};
        addplot [domain = a6:a7,samples=2,color=blue]
        {k};
        addplot [domain = a7:a8,samples=2,color=blue]
        {k*(a8-x)/(a8-a7)};
        addplot [domain = a8:a9,samples=2,color=blue]
        {0};
        
        %legend{$B^3_0(t)$,$B^3_1(t)$,$B^3_2(t)$,$B^3_3(t)$}
    end{axis}
end{tikzpicture}
end{document}

Answered by Michel Janssens on June 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP