简单的拉格朗日松弛算法 c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            double ub=10;
            double step = 0.01;
            double [,] x = new double[1000,2 ];
            double [,] u = new double[1000, 2];
            u[0,0]=0;
            u[0,1]=0;
            double[] z = new double[1000];
            double [] w=new double[1000];
            
            double[] ee=new double[1000];
            double [] p1=new double[1000];
            double [] p2 = new double[1000];

                   
            for (int i = 0; i < 900;i++ )
            {
                if (3 + u[i, 0] - 2 * u[i, 1] > 0)
                {    
                    x[i, 0] = 0;
                }
                else
                {
                    x[i, 0] = 3;
                }


                if (4 - 3 * u[i, 0] - 2 * u[i, 1] > 0)
                {
                    x[i, 1] = 0;
                }
                else    
                {
                    x[i, 1] = 3;  
                }

                Console.WriteLine("x1:{0} x2:{1}", x[i,0],x[i,1]);


                z[i]=3*x[i,0]+4*x[i,1];
                p1[i] = x[i,0]-3*x[i,1];
                p2[i]=5-2*x[i,0]-x[i,1];


                ee[i] = System.Math.Sqrt(System.Math.Pow(p1[i], 2) + System.Math.Pow(p2[i], 2));
                w[i] = z[i] + u[i , 0] * p1[i] + u[i , 1] * p2[i];
                                      
                Console.WriteLine("w:{0}", w[i]);

                u[i + 1, 0] = u[i, 0] + p1[i]*step * (ub - w[i]) / (ee[i]);
                u[i + 1, 1] = u[i, 1] + p2[i]* step * (ub - w[i]) / (ee[i]);

                Console.WriteLine("u1:{0} u2:{1}", u[i, 0], u[i, 1]);
                Console.WriteLine("_________");
            }


            while (-p1[900]>=0)
            {
                x[900, 1] = x[900, 1]-1;
            
            }
            while  (-p2[900] >= 0)
            {
                x[900, 0] = x[900, 0] - 1;

            }

            Console.WriteLine("x1:{0} x2:{1}", x[500, 0], x[500, 1]);
            Console.Read();
        }
    }
}


转载于:https://www.cnblogs.com/elitez/archive/2011/04/21/2024148.html

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值