绘制 sigmoid函数

// 用来计算从-4到4之间的sigmoid函数值的静态函数
public   class  Uitility
{
    
public static PointF[] GetPoints()
    
{
        PointF[] mypos
=new PointF[400];
        
int j=0;
        
for(double i=-4;i<=4;i+=0.02)
        
{
            mypos[j]
= new PointF((float)i,(float)Sigmoid(i));
            j
++;
        }

        
return mypos;
    }


    
public static double Sigmoid(double x)
    
{
        
return 1/(1+Math.Pow(Math.E,-x));
    }

}



// 调用函数,完成函数的picturebox1上的绘制

Graphics grfx
= pictureBox1.CreateGraphics();
        
int  picwidth = pictureBox1.Width;
int  picheight = pictureBox1.Height;

float  midx = ( float )picwidth / 2 ;
float  midy = ( float )picheight / 2 ;


Pen bb
= new  Pen(Brushes.Black, 2 );

grfx.DrawLine(Pens.Red,
new  Point( 0 ,picheight - 1 ), new  Point(picwidth,picheight - 1 )); // 横坐标
grfx.DrawLine(Pens.Red, new  Point(( int )midx,picheight), new  Point(( int )midx, 0 ));

PointF[] cc
= Uitility.GetPoints();
PointF[] realone
= new  PointF[cc.Length];
int  cclen = cc.Length;    

// 将与坐标无关的数值转换成与坐标相关的点
for ( int  i = 0 ;i < cclen;i ++ )
{
    
float fx=cc[i].X*picwidth/8+midx;
    
float fy=cc[i].Y*picheight; 
    realone[i]
=new PointF(fx,-fy+picheight);
}

grfx.DrawLines(bb,realone);
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值