博文

guass消去求线性方程的根(2006-04-19 10:34:00)

摘要://目标   用高斯消去法求线性方程的根 //C++实现 #include"stdio.h"#include"iostream"#include"conio.h" using namespace std; class guass{      public:             guass(int n,double t);             void begin();    void display();                                 int n;            // GUASS迭代的规模               double e;              double a[4][4];              double b[4];}; guass::guass(int m,double t){     n=m;  e=t;&......

阅读全文(4393) | 评论:2

链表遍历,链表倒置(2006-04-03 13:11:00)

摘要:print算法实现链表的遍历;reverse 算法实现 链表的倒置,并让链表的头指针L指向新表的表头。   原代码: // test02_2#include "linklist.h" link l;void Print(link l){ link p;    p=l;//Blank 1    while (P!=NULL)    {     visite_snode(P,1);     p=p->next;//Blank 2     }} void Reverse(link &L){ link h,u; h=NULL; while(l!=NULL)//Blank 3 {  u=L;  L=L->next;  u->next=h;                h=u;//Blank 4 } l=u;//Blank 5} void main(){ load_hsllist(l); comput_sllist_card(l,50,100);  disp_hsllist("Sllist",l); Print(l);    Reverse(l->next);    comput_sllist_card(l,50,250);     disp_hsllist("Reversed",l);} ......

阅读全文(5563) | 评论:0

牛顿下山法  求非线性方程的根(2006-03-29 21:51:00)

摘要:目标:       用牛顿下山法,求非线性方程x*x*x-x-1=0,的根。   要求:        输入,初值,误差限,最大迭代次数,最大下山次数;        输出,近似根以及下山因子; 时间:          3.39日晚   代码(C++实现): //牛顿下山法 //非线性方程求根   #include"iostream"#include"stdlib.h"#include"math.h"#include"conio.h"using namespace std; double function(double x){       return x*x*x-x-1;       } double function_dao(double x){       return 3*x*x-1;       }void error_output(int p){     switch(p)     {              case 1:cout<<"超出下山次数,请另选择初值!"<<endl;              case 2:cout<<"超出迭代次数,失败!";       ......

阅读全文(10612) | 评论:15

romberg 算法求数值积分(2006-03-29 21:45:00)

摘要:目标:       用龙贝格(romberg)算法,计算  sin(x)/x 的积分; 要求:      输入,积分区间,误差限;      输出,序列T,S,C,及积分结果   实现:             流程图(略);   时间:3.29  晚7.0-8.0   代码(C++实现): #include"stdlib.h"#include"math.h"#include"iostream" using namespace std; double function( double x){ return x==0?1:sin(x)/x;} int print_romberg(double a,double b,double e){   int k=1;   double h=b-a;   double t1,t2,s1,s2,c1,c2,s,x,r2,r1;   t1=h*(function(a)+function(b))/2;   goto loop;      loop:   s=0;   x=a+h/2;   do{           s=s+function(x);           x=x+h;           }while(x<b);   t2=t1/2+h*s/2;   s2=t2+(t2-t......

阅读全文(6379) | 评论:0