请c/c++高手看一下关于sor程序的问题

来源:百度知道 编辑:UC知道 时间:2024/06/26 01:28:27
请高手看看为什么无法运行?跪谢
好像是sor函数有问题
#include "stdlib.h"
#include "stdio.h"
#include "nrutil.h"
#include "time.h"
#include <math.h>
#include "stddef.h"
#define MAXITS 1000
#define NR_END 1
#define FREE_ARG char*
#define EPS 1.0e-5
void sor(double **a,double **b,double **c,double **d,double **e,double **f,double **u,int jmax,double rjac)
{
void nrerror(char error_text[]);
int ipass,j,jsw,l,lsw,n;
double anorm,anormf=0.0,omega=1.0,resid;
for(j=2;j<jmax;j++)
for(l=2;l<jmax;l++)
anormf+=fabs(f[j][l]);
for(n=1;n<=MAXITS;n++)
{
anorm=0.0;
jsw=1;
for(ipass=1;ipass<=2;ipass++)
{
lsw=jsw;
for(j=2;j<jmax;j++)
{
for(l=lsw+1;l<jmax;l+=2)
{
resid=a[j][l]*u[j+1][l]+b[j][l]*u[j-1][l]+c[j][l]*u[

错误不在sor,在这里:
for(j=0;j<m;j++)
{
for(l=0;l<n;l++)
{
a[j][l]=rand();
b[j][l]=rand();
c[j][l]=rand();
d[j][l]=rand();
e[j][l]=rand();
f[j][l]=rand();
u[j][l]=0.0;
}
}
怀疑你的dmatrix函数写的有问题,代码写得很乱,不知道在干什么。估计是内存分配有问题。我这里的运行时错误是访问了非法地址0。环境是VS 2005.

我把你的程序稍微修改了一下,可以看得比较清楚错误的地方。
#include <stdlib.h>
#include <stdio.h>
//#include "nrutil.h"
#include <time.h>
#include <math.h>
#include <stddef.h>

#define MAXITS 1000
#define NR_END 1
#define FREE_ARG char*
#define EPS 1.0e-5

void nrerror(char error_text[]);

void sor(double **a,double **b,double **c,double **d,double **e,double **f,double **u,int jmax,double rjac)
{
int ipass,j,jsw,l,lsw,n;
double anorm,anormf=0.0,omega=1.0,resid;

printf("enter sor\n");

fo