矩阵填充(求解b = A * x) - >使用数字食谱 [英] matrix stuff (solving b = A*x) --> using numerical recipes
问题描述
我用数字食谱制作了一个程序。看起来我不被允许
从数字食谱中分发源代码,但它不应该是
甚至是必要的。
我的问题是我对指针,指针等等没有很多经验,我有4个编译器警告+我不完全
了解如何构建这个紧凑矩阵 (见后面)。
我也不完全确定我是否理解正确的文字...到目前为止
我的程序看起来像这样:
#include< math.h>
#include" nrutil.h"
/ *定义* /
#define number_of_rows 7
#define TINY 1.0e-20
#define SWAP(a,b){dum =( a);(a)=(b);(b)= dum;}
/ *原型* /
void banmul(float ** a ,unsigned long n,int left,int right,float x [],
float b []);
void bandec(float ** a,unsigned long n, int left,int right,float ** al,
unsigned long indx [],float * d);
void banbks(float ** a,unsigned long n, int left,int right,float ** al,
unsigned long indx [],float b []);
/ *主程序启动* /
int main(无效)
{
/ *声明* /
double x [number_of_rows],b [number_of_rows]; //记得我们已经解决了b = A * x
/ *初始化* /
double a [] [number_of_rows] = // number_of_cols = number_of_rows
{
{3.,1.,0.,0.,0.,0.,0 。},
{4.,1.,5.,0.,0.,0.,0。},
{9.,2.,6 。,5.,0.,0.,0。},
{0.,3.,5.,8.,9.,0.,0。},
{0.,0.,7.,9.,3.,2.,0。},
{0.,0.,0.,3。,8。 ,4。,6。},
{0,0.0,0.0,2。,4.,4。}
};
banmul(a,number_of_rows,2,1,x,b);
printf(" \ nFinishing program now.\\\
\ n");
}
如果您需要了解任何信息,可以在此处阅读:
章开始,带有Band diagonal system,p.52。
你可以看到我的二维矩阵是一样的......文字讲述了转换
将矩阵转换为更紧凑的形式......我必须承认我需要一些帮助
因为我不理解文字: - (
我的编译器警告(不知道该怎么做):
----
警告C4047: ''function'':''float **''间接水平不同
来自''double [7] [7]'
警告C4024:''banmul'':正式和实际参数1的不同类型
警告C4133:''函数'':不兼容的类型 - 来自''double [7]''
''float *''
警告C4133:''function'':不兼容的类型 - 从''double [7]''到
''浮动*''
----
问题在于:banmul(a ,. ...)" ;;
所以,一般来说,我真的不明白我在做什么:-(
x-数组(向量)未定义。如果有人能给我看一个如何解决这个矩阵系统的例子,我会非常高兴(你只需要你想要的任何你想要的x:x = [2, 5,2,1,6,2,1]或者其他......
AFAIK来自数字配方的文字和我的代码应该足够了
你了解我的代码,我希望有人可以给我一些提示
可以让我更接近解决方案。
提前感谢任何人(希望如此)好的)投入......
祝你好运/ Med venlig hilsen
Martin J?rgensen
-
---------------------------------------------- -----------------------------
Martin J?rgensen的故乡 - http://www.martinjoergensen.dk
推荐答案
Martin J?rgensen说:
Martin J?rgensen said:
我的问题是我对指针不是很有经验,指向
指针等我得到4个编译器警告+我不完全理解如何建立这个紧凑矩阵 (见后文)。
双精度不是浮点数,数组不是指针。
void banmul(float ** a,unsigned long n,int left,int right,float x [],
浮动b []);
/ *声明* /
double x [number_of_rows],b [number_of_rows]; //记住我们正在解决b = A * x
/ *初始化* /
double a [] [number_of_rows] = // number_of_cols = number_of_rows
{
[...]};
banmul(a,number_of_rows,2,1,x,b);
My problem is that I''m not very experienced with pointers, pointers to
pointers and the like and I got 4 compiler warnings + I don''t completely
understand how to build this "compact matrix" (see later).
doubles are not floats, and arrays are not pointers.
void banmul(float **a, unsigned long n, int left, int right, float x[],
float b[]); /* declaration */
double x[number_of_rows], b[number_of_rows]; // remember that we''re
solving "b = A * x"
/* initialisation */
double a[][number_of_rows] = // number_of_cols = number_of_rows
{ [...] };
banmul(a, number_of_rows, 2, 1, x, b);
banmul对参数1采用float **,但实际上你传递了一个
double(*)[7],这几行不同苹果树。
banmul对参数5和6采用浮动*,你试图通过它
double *。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
banmul takes float ** for parameter 1, but you''re actually passing it a
double (*)[7], which is not the same thing by several rows of apple trees.
banmul takes float * for parameters 5 and 6, and you are trying to pass it
double *.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Martin J?rgensen< un ** *******@spam.jay.net>写道:
[...]
Martin J?rgensen <un*********@spam.jay.net> writes:
[...]
警告C4047:''function'':''float **''间接水平与'间接'不同'double [7] [7]''
warning C4047: ''function'' : ''float **'' differs in levels of
indirection from ''double [7][7]''
数组不是指针,2维数组不是指向
指针的指针。 comp.lang.c FAQ位于< http://www.c-faq.com/> ;;以第6节阵列和指针开始
。
-
Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>
San迭戈超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
Arrays are not pointers, and 2-dimensional arrays are not pointers to
pointers. The comp.lang.c FAQ is at <http://www.c-faq.com/>; start
with section 6, "Arrays and Pointers".
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Richard Heathfield写道:
Richard Heathfield wrote:
Martin J?rgensen说:
-snip-
Martin J?rgensen said: -snip-
banmul(a,number_of_rows,2,1,x,b);
banmul(a, number_of_rows, 2, 1, x, b);
banmul需要浮动**参数1,但实际上你传递了一个
double(*)[7],这与几排苹果树不一样。
banmul takes float ** for parameter 1, but you''re actually passing it a
double (*)[7], which is not the same thing by several rows of apple trees.
该死...我明白你在写什么。我只是不知道如何修复
这个问题......你/有人请帮忙吗?
我试过了:
int main(无效)
{
int i;
/ *声明* /
浮动x [number_of_rows],b [number_of_rows]; //记住我们是'b $ b'解决'b = A * x"
浮动** a = malloc((number_of_rows)* sizeof(浮动*)) ;
a [0] = malloc((number_of_rows * number_of_rows)* sizeof(floa t));
for(i = 1; i< number_of_rows ; i ++)
a [i] = a [i-1] + number_of_rows + 1;
a = //
{
{3.,1.,0.,0.,0.,0.,0。},
{4.,1。,5.,0 。,0.,0.,0。},
{9.,2.,6.,5.,0.,0.,0。},
{0.,3.,5.,8.,9.,0.,0。},
{0.,0.,7.,9。,3。,2。 ,0。},
{0.,0。,0.,3.,8.,4.,6。},
{0.,0。 ,0.,0.,2.,4.,4。}
};
banmul(a,number_of_rows,2,1,x, b);
printf(\ nFinishing program now.\\\
\ n);
}
>
这给出了3个问题:
1)警告C4047:''初始化'':''浮动**''的水平不同$
malloc( (number_of_rows)* sizeof(float *));
2)警告C4047:''='':''float *''的间接等级与
不同
''int'' - 这是一行:a [0] =
malloc((number_of_rows * number_of_rows)* sizeof(floa t));
>
3)语法错误:''{'' - 我现在有一个初始化2D
&a的问题 - 带有这种符号的矩阵......
banmul对参数5和6采用float *,你试图传递它
double *。
Damn... I understand what you''re writing. I just don''t know how to fix
the problem... Could you/somebody please help?
I tried:
int main(void)
{
int i;
/* declaration */
float x[number_of_rows], b[number_of_rows]; // remember that we''re
solving "b = A * x"
float **a = malloc((number_of_rows)*sizeof(float*));
a[0] = malloc((number_of_rows*number_of_rows)*sizeof(floa t));
for (i = 1; i < number_of_rows ;i++)
a[i] = a[i-1] + number_of_rows+1;
a = //
{
{3.,1.,0.,0.,0.,0.,0.},
{4.,1.,5.,0.,0.,0.,0.},
{9.,2.,6.,5.,0.,0.,0.},
{0.,3.,5.,8.,9.,0.,0.},
{0.,0.,7.,9.,3.,2.,0.},
{0.,0.,0.,3.,8.,4.,6.},
{0.,0.,0.,0.,2.,4.,4.}
};
banmul(a, number_of_rows, 2, 1, x, b);
printf("\nFinishing program now.\n\n");
}
This gives 3 problems:
1) warning C4047: ''initializing'' : ''float **'' differs in levels of
indirection from ''int'' - this is the line: float **a =
malloc((number_of_rows)*sizeof(float*));
2) warning C4047: ''='' : ''float *'' differs in levels of indirection from
''int'' - this is the line: a[0] =
malloc((number_of_rows*number_of_rows)*sizeof(floa t));
3) syntax error : ''{'' - I now have a problem with initializing the 2D
"a"-matrix with this notation...
banmul takes float * for parameters 5 and 6, and you are trying to pass it
double *.
该死的......愚蠢的错误。我只是通过更改定义来解决这个问题。
最好的问候/ Med venlig hilsen
Martin J?rgensen
-
------------------------------------------- --------------------------------
Martin J?rgensen的家 - http://www.martinjoergensen.dk
这篇关于矩阵填充(求解b = A * x) - >使用数字食谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!