fun.m

来自「是1-n-1和2-n-1型的基于MATLAB的标准BP算法程序」· M 代码 · 共 55 行

M
55
字号
%'s','s-shape','5*s-shape','gauss1','gauss2','cos','sin+cos'
function y=fun(x,flag,graph)
a=4; b=3;
switch graph
    case 's'
        switch flag
            case 0
                y=x;
            otherwise
                y=1;
        end
    case 's-shape'
        switch flag
            case 0
                y=1./(1+exp(-x));
            otherwise
                y=exp(-x)./(1+exp(-x)).^2;
        end
    case '5*s-shape'
        switch flag
            case 0
                y=10./(1+exp(-x));
            otherwise
                y=10.*exp(-x)./(1+exp(-x)).^2;
        end
    case 'gauss1'
        switch flag
            case 0
                y=exp(-x.^2/a);
            otherwise
                y=-2/a.*x.*exp(-x.^2/a);
        end
    case 'gauss2'
        switch flag
            case 0
                y=b+exp(-x.^2/a);
            otherwise
                y=-2/a.*x.*exp(-x.^2/a);
        end
    case 'cos'
        switch flag
            case 0
                y=cos(x);
            otherwise
                y=-sin(x);
        end
    case 'sin+cos'
        switch flag
            case 0
                y=sin(x)+cos(x);
            otherwise
                y=cos(x)-sin(x);
        end
end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?