未处理的“System.IndexOutOfRangeException”类型的异常出现在 calculate.exe 中

laojx 2006-03-23 04:21:54
未处理的“System.IndexOutOfRangeException”类型的异常出现在 calculate.exe 中
其他信息: 索引超出了数组界限。

百思不得其解啊,望高人指教!

未处理的异常: System.IndexOutOfRangeException: 索引超出了数组界限。
at calculate.Form1.qrtt(Int32 n, Double[] a, Double[] u, Double[] v, Double eps, Int32 jt) in e:\c#\解方程\calculate\form1.cs:line 217
at calculate.Form1.button1_Click(Object sender, EventArgs e) in e:\c#\解方程\calculate\form1.cs:line 364
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Fo程序“[5508] calculate.exe”已退出,返回值为 0 (0x0)。
rms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at calculate.Form1.Main() in e:\c#\解方程\calculate\form1.cs:line 205
...全文
1274 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
laojx 2006-03-24
  • 打赏
  • 举报
回复
顶,请大家帮忙
laojx 2006-03-23
  • 打赏
  • 举报
回复
是这行超界了,但是不清楚怎么解决:(
lovefootball 2006-03-23
  • 打赏
  • 举报
回复
太长了
设个断点跟踪一下
肯定是数组超界了
at calculate.Form1.qrtt(Int32 n, Double[] a, Double[] u, Double[] v, Double eps, Int32 jt) in e:\c#\解方程\calculate\form1.cs:line 217
看看这行
laojx 2006-03-23
  • 打赏
  • 举报
回复
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private int qrtt(int n,double[] a,double[] u,double[] v,double eps,int jt)
{
int m,it,i,j,k,l,ii,jj,kk,ll;
double b,c,w,g,xy,p,q,r,x,s,e,f,z,y;
it=0;
m=n;
while(m!=0)
{
l=m-1;
while((l>0)&&(Math.Abs(a[l*n+l-1])>eps*(Math.Abs(a[(l-1)*n+l-1])+Math.Abs(a[l*n+1]))))l=l-1;
ii=(m-1)*n+m-1;
jj=(m-1)*n+m-2;
kk=(m-2)*n+m-1;
ll=(m-2)*n+m-2;
if(l==m-1)
{
u[m-1]=a[(m-1)*n+m-1];
v[m-1]=0.0;
m=m-1;
it=0;
}
else if(l==m-2)
{
b=-(a[ii]+a[ll]);
c=a[ii]*a[ll]-a[jj]*a[kk];
w=b*b-4.0*c;
y=Math.Sqrt(Math.Abs(w));
if(w>0.0)
{
xy=1.0;
if(b<0.0)xy=-1.0;
u[m-1]=(-b-xy*y)/2.0;
u[m-2]=c/u[m-1];
v[m-1]=0.0;
v[m-2]=0.0;
}
else
{
u[m-1]=-b/2.0;
u[m-2]=u[m-1];
v[m-1]=y/2.0;
v[m-2]=-v[m-1];
}
m=m-2;it=0;
}
else
{
if(it>=jt)
{
MessageBox.Show("失败!");
return(-1);
}
it=it+1;
for(j=l+2;j<=m-1;j++)
a[j*n+j-2]=0.0;
for(j=l+3;j<=m-1;j++)
a[j*n+j-3]=0.0;
for(k=1;k<=m-2;k++)
{
if(k!=1)
{
p=a[k*n+k-1];
q=a[(k+1)*n+k-1];
r=0.0;
if(k!=m-2)r=a[(k+2)*n+k-1];
}
else
{
x=a[ii]+a[ll];
y=a[ll]*a[ii]-a[kk]*a[jj];
ii=l*n+1;
jj=l*n+l+1;
kk=(l+1)*n+1;
ll=(l+1)*n+l+1;
p=a[ii]*(a[ii]-x)+a[jj]*a[kk]+y;
q=a[kk]*(a[ii]+a[ll]-x);
r=a[kk]*a[(l+2)*n+l+1];
}
if((Math.Abs(p)+Math.Abs(q)+Math.Abs(r))!=0.0)
{
xy=1.0;
if(p<0.0)xy=-1.0;
s=xy*Math.Sqrt(p*p+q*q+r*r);
if(k!=1)a[k*n+k-1]=-s;
e=-q/s;
f=-r/s;
x=-p/s;
y=-x-f*r/(p+s);
g=e*r/(p+s);
z=-x-e*q/(p+s);
for(j=k;j<=m-1;j++)
{
ii=k*n+j;
jj=(k+1)*n+j;
p=x*a[ii]+e*a[jj];
q=e*a[ii]+y*a[jj];
r=f*a[ii]+g*a[jj];
if(k!=m-2)
{
kk=(k+2)*n+j;
p=p+f*a[kk];
r=r+z*a[kk];
a[kk]=r;
}
a[jj]=q;
a[ii]=p;
}
j=k+3;
if(j>=m-1)j=m-1;
for(i=1;i<=j;i++)
{
ii=i*n+k;
jj=i*n+k+1;
p=x*a[ii]+e*a[jj];
q=e*a[ii]+y*a[jj];
r=f*a[ii]+g*a[jj];
if(k!=m-2)
{
kk=i*n+k+2;
p=p+f*a[kk];
q=q+g*a[kk];
r=r+z*a[kk];
a[kk]=r;
}
a[jj]=q;
a[ii]=p;
}
}
}
}
}
return(1);
}


private void button1_Click(object sender, System.EventArgs e)
{
double a,b,c,d,A,B,C,D;
a=Convert.ToDouble(this.R.Text);
b=Convert.ToDouble(this.angle123.Text.ToString());
c=Convert.ToDouble(this.T1.Text);
d=Convert.ToDouble(this.T2.Text);

A=1/(2688*(a*a*a)*Math.Atan(b));
B=1/(240*a*a);
C=1/(24*a*Math.Atan(b));
D=d-c;

int i,jt,n;
double[] xr=new double[4];
double[] xi=new double[4];
double[] h=new double[]{D,0.5,C,B,A};
double eps;
eps=0.001;
jt=60;
n=4;
i=qrtt(n,h,xr,xi,eps,jt);
if(i>0)
{
for(i=0;i<=3;i++)
listBox2.Items.Add("x("+i.ToString() + ")=" + xr[i].ToString("e") + " " + xi[i].ToString("e")+"J" );
}
}

}
}
laojx 2006-03-23
  • 打赏
  • 举报
回复
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace calculate
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label angle;
private System.Windows.Forms.TextBox T2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox T1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.TextBox R;
private System.Windows.Forms.TextBox angle123;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.R = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.angle = new System.Windows.Forms.Label();
this.T2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.T1 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.listBox2 = new System.Windows.Forms.ListBox();
this.angle123 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// R
//
this.R.Location = new System.Drawing.Point(48, 40);
this.R.Name = "R";
this.R.Size = new System.Drawing.Size(48, 21);
this.R.TabIndex = 0;
this.R.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 1;
this.label1.Text = "请输入:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 44);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(24, 16);
this.label2.TabIndex = 1;
this.label2.Text = "R:";
//
// angle
//
this.angle.Location = new System.Drawing.Point(120, 44);
this.angle.Name = "angle";
this.angle.Size = new System.Drawing.Size(48, 16);
this.angle.TabIndex = 1;
this.angle.Text = "角度:";
//
// T2
//
this.T2.Location = new System.Drawing.Point(168, 80);
this.T2.Name = "T2";
this.T2.Size = new System.Drawing.Size(48, 21);
this.T2.TabIndex = 0;
this.T2.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(138, 84);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(23, 16);
this.label3.TabIndex = 1;
this.label3.Text = "T‘";
//
// T1
//
this.T1.Location = new System.Drawing.Point(48, 80);
this.T1.Name = "T1";
this.T1.Size = new System.Drawing.Size(48, 21);
this.T1.TabIndex = 0;
this.T1.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(20, 85);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 16);
this.label4.TabIndex = 1;
this.label4.Text = "T1:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(88, 120);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "计算";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 160);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96, 16);
this.label5.TabIndex = 1;
this.label5.Text = "计算结果如下:";
//
// listBox2
//
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(24, 184);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(224, 100);
this.listBox2.TabIndex = 5;
//
// angle123
//
this.angle123.Location = new System.Drawing.Point(168, 40);
this.angle123.Name = "angle123";
this.angle123.Size = new System.Drawing.Size(48, 21);
this.angle123.TabIndex = 6;
this.angle123.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(264, 309);
this.Controls.Add(this.angle123);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.R);
this.Controls.Add(this.label2);
this.Controls.Add(this.angle);
this.Controls.Add(this.T2);
this.Controls.Add(this.label3);
this.Controls.Add(this.T1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.listBox2);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧