gpt4 book ai didi

c++ - *** 检测到堆栈粉碎 *** : in gaussian elimination

转载 作者:太空狗 更新时间:2023-10-29 20:09:23 25 4
gpt4 key购买 nike

<分区>

我正在用 C++ 编写代码,用于教学共振的高斯消元法。编译时没有错误,但是在执行程序时出现堆栈粉碎错误。

这是我写的:

#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(){
int i,j,l,n;
double *c;
int *indice;
double a[2][2];

n=2;
a[1][1]=1;
a[1][2]=2;
a[2][1]=3;
a[2][2]=4;

c=new double[n];
indice=new int[n];
/*Inizialize indice*/
for(i=0;i<n;i++){indice[i]=i;}
/*find scaling factor*/
for (i=0;i<n;i++){
double c1=0;
for (j=0;j<n;j++){
double c0=abs(a[i][j]);
if(c0>c1) c1=c0;}
c[i]=c1;}
/*find pivot*/
int k=0;
for(i=0;i<n-1;i++){
double pi1=0;
for(j=i;j<n;j++){
double pi0=abs(a[indice[j]][i]);
pi0/=c[indice[j]];
if(pi0>pi1){
pi1=pi0;
k=j;}}
/*interchange rows according to pivoting order*/
int itemp=indice[i];
indice[i]=indice[k];
indice[k]=itemp;
for(j=i+1;j<n;j++){
double pj=a[indice[j]][i]/(a[indice[i]][i]);
/*recording pivot ratio below diagonal*/
a[indice[j]][i]=pj;
/*modify other elements accordingly*/
for(l=i+1;l<n;l++){
a[indice[j]][l]-=pj*a[indice[i]][l];}}}

delete c;
delete indice;
return 0;}

这是什么意思,我的错误在哪里?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com