不包含适合于入口点的静态 main 方法
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespa...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 仿真
{
class Program
{
public Double F(Double t, Double y)
{
return -y * y;
}
public void Main()
{
Double Emin, Emax;
Emin = 0.000001;
Emax = 0.00001;
Double tm = 0, xm = 1, h = 0.1, k1, k2, k3, k4, k5, xm1, em;
for (; ; )
{
k1 = F(tm, xm);
k2 = F(tm + h / 3, xm + h * k1 / 3);
k3 = F(tm + h / 2, xm + h * (k1 + k2) / 6);
k4 = F(tm + h / 2, xm + h * (k1 + 3 * k3) / 8);
k5 = F(tm + h, xm + h * (k1 - 3 * k3 + 4 * k4) / 2);
xm1 = xm + h * (k1 + 4 * k4 + k5);
em = xm + h * (2 * k1 - 9 * k3 + 8 * k4 - k5) / 6;
if (em < Emin)
{
h = 2 * h;
Console.WriteLine("当E<Emin的时候:Yn={0}",xm1);
continue;
}
if (em< Emax)
{
Console.WriteLine("满足条件的数值解:Yn={0}",xm1);
break;
}
h = h / 2;
}
}
}
}
请问如何解决啊? 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 仿真
{
class Program
{
public Double F(Double t, Double y)
{
return -y * y;
}
public void Main()
{
Double Emin, Emax;
Emin = 0.000001;
Emax = 0.00001;
Double tm = 0, xm = 1, h = 0.1, k1, k2, k3, k4, k5, xm1, em;
for (; ; )
{
k1 = F(tm, xm);
k2 = F(tm + h / 3, xm + h * k1 / 3);
k3 = F(tm + h / 2, xm + h * (k1 + k2) / 6);
k4 = F(tm + h / 2, xm + h * (k1 + 3 * k3) / 8);
k5 = F(tm + h, xm + h * (k1 - 3 * k3 + 4 * k4) / 2);
xm1 = xm + h * (k1 + 4 * k4 + k5);
em = xm + h * (2 * k1 - 9 * k3 + 8 * k4 - k5) / 6;
if (em < Emin)
{
h = 2 * h;
Console.WriteLine("当E<Emin的时候:Yn={0}",xm1);
continue;
}
if (em< Emax)
{
Console.WriteLine("满足条件的数值解:Yn={0}",xm1);
break;
}
h = h / 2;
}
}
}
}
请问如何解决啊? 展开
展开全部
1. main函数应定义为static void main(),实现静态main
2.Double改为double,是一个双精度类型
3.实例化Program类以引用F()
大概改成这样(只是修改的例子,没去试):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 仿真
{
class Program
{
public double F(double t, double y)
{
return -y * y;
}
static void Main()
{
double Emin, Emax;
Emin = 0.000001;
Emax = 0.00001;
double tm = 0, xm = 1, h = 0.1, k1, k2, k3, k4, k5, xm1, em;
Program myClass = new Program();
for (; ; )
{
k1 = myClass.F(tm, xm);
k2 = myClass.F(tm + h / 3, xm + h * k1 / 3);
k3 = myClass.F(tm + h / 2, xm + h * (k1 + k2) / 6);
k4 = myClass.F(tm + h / 2, xm + h * (k1 + 3 * k3) / 8);
k5 = myClass.F(tm + h, xm + h * (k1 - 3 * k3 + 4 * k4) / 2);
xm1 = xm + h * (k1 + 4 * k4 + k5);
em = xm + h * (2 * k1 - 9 * k3 + 8 * k4 - k5) / 6;
if (em < Emin)
{
h = 2 * h;
Console.WriteLine("当E<Emin的时候:Yn={0}", xm1);
continue;
}
if (em < Emax)
{
Console.WriteLine("满足条件的数值解:Yn={0}", xm1);
break;
}
h = h / 2;
}
}
}
}
2.Double改为double,是一个双精度类型
3.实例化Program类以引用F()
大概改成这样(只是修改的例子,没去试):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 仿真
{
class Program
{
public double F(double t, double y)
{
return -y * y;
}
static void Main()
{
double Emin, Emax;
Emin = 0.000001;
Emax = 0.00001;
double tm = 0, xm = 1, h = 0.1, k1, k2, k3, k4, k5, xm1, em;
Program myClass = new Program();
for (; ; )
{
k1 = myClass.F(tm, xm);
k2 = myClass.F(tm + h / 3, xm + h * k1 / 3);
k3 = myClass.F(tm + h / 2, xm + h * (k1 + k2) / 6);
k4 = myClass.F(tm + h / 2, xm + h * (k1 + 3 * k3) / 8);
k5 = myClass.F(tm + h, xm + h * (k1 - 3 * k3 + 4 * k4) / 2);
xm1 = xm + h * (k1 + 4 * k4 + k5);
em = xm + h * (2 * k1 - 9 * k3 + 8 * k4 - k5) / 6;
if (em < Emin)
{
h = 2 * h;
Console.WriteLine("当E<Emin的时候:Yn={0}", xm1);
continue;
}
if (em < Emax)
{
Console.WriteLine("满足条件的数值解:Yn={0}", xm1);
break;
}
h = h / 2;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询