有限元求解柏松方程。本文采用FORTRAN語言編制程序。程序中大部分變量采用有名公共區存儲方式存儲,這樣可以減少內存占用量。 IFG:生成有限元網格信息,即元素節點局部編碼與總體編碼對照表,節點實際坐標,邊界節點編碼與邊界點上的已知值 GKD:生成總剛一維存儲對角元的地址,計算總剛一維存儲長度 FIXP:設置已知節點函數值 GK(NI,NJ,ADJ,AIJ):單元剛度矩陣計算 GF(NI,N,M,LE,YI,FE):單元列陣的計算 AK(I,J,AIJ):總剛度矩陣元素迭加 QEB:總剛度矩陣和總列陣合成 BDE:邊界條件處理 SOLGS:Gauss-Seidel迭代法求解方程組 UDIFF(NI,NFLAG,UDIF,LE,ADJ):標準元素內形狀函數導數計算 DIFF:節點上 , 加權平均
上傳時間: 2017-09-12
上傳用戶:問題問題
旅行商問題(Travelling Salesman Problem, 簡記TSP,亦稱貨郎擔問題):設有n個城市和距離矩陣D=[dij],其中dij表示城市i到城市j的距離,i,j=1,2 … n,則問題是要找出遍訪每個城市恰好一次的一條回路并使其路徑長度為最短。
標簽: Travelling Salesman Problem TSP
上傳時間: 2017-09-14
上傳用戶:彭玖華
#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct /*運動員*/ { char name[20]; int score; /*分數*/ int range; /**/ int item; /*項目*/ }ATH; typedef struct schoolstruct /*學校*/ { int count; /*編號*/ int serial; /**/ int menscore; /*男選手分數*/ int womenscore; /*女選手分數*/ int totalscore; /*總分*/ ATH athlete[MaxSize]; /**/ struct schoolstruct *next; }SCH; int nsc,msp,wsp; int ntsp; int i,j; int overgame; int serial,range; int n; SCH *head,*pfirst,*psecond; int *phead=NULL,*pafirst=NULL,*pasecond=NULL; void create(); void input () { char answer; head = (SCH *)malloc(sizeof(SCH)); /**/ head->next = NULL; pfirst = head; answer = 'y'; while ( answer == 'y' ) { Is_Game_DoMain: printf("\nGET Top 5 when odd\nGET Top 3 when even"); printf("\n輸入運動項目序號 (x<=%d):",ntsp); scanf("%d",pafirst); overgame = *pafirst; if ( pafirst != phead ) { for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ ) { if ( overgame == *pasecond ) { printf("\n這個項目已經存在請選擇其他的數字\n"); goto Is_Game_DoMain; } } } pafirst = pafirst + 1; if ( overgame > ntsp ) { printf("\n項目不存在"); printf("\n請重新輸入"); goto Is_Game_DoMain; } switch ( overgame%2 ) { case 0: n = 3;break; case 1: n = 5;break; } for ( i = 1 ; i <= n ; i++ ) { Is_Serial_DoMain: printf("\n輸入序號 of the NO.%d (0<x<=%d): ",i,nsc); scanf("%d",&serial); if ( serial > nsc ) { printf("\n超過學校數目,請重新輸入"); goto Is_Serial_DoMain; } if ( head->next == NULL ) { create(); } psecond = head->next ; while ( psecond != NULL ) { if ( psecond->serial == serial ) { pfirst = psecond; pfirst->count = pfirst->count + 1; goto Store_Data; } else { psecond = psecond->next; } } create(); Store_Data: pfirst->athlete[pfirst->count].item = overgame; pfirst->athlete[pfirst->count].range = i; pfirst->serial = serial; printf("Input name:) : "); scanf("%s",pfirst->athlete[pfirst->count].name); } printf("\n繼續輸入運動項目(y&n)?"); answer = getchar(); printf("\n"); } } void calculate() /**/ { pfirst = head->next; while ( pfirst->next != NULL ) { for (i=1;i<=pfirst->count;i++) { if ( pfirst->athlete[i].item % 2 == 0 ) { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 5;break; case 2:pfirst->athlete[i].score = 3;break; case 3:pfirst->athlete[i].score = 2;break; } } else { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 7;break; case 2:pfirst->athlete[i].score = 5;break; case 3:pfirst->athlete[i].score = 3;break; case 4:pfirst->athlete[i].score = 2;break; case 5:pfirst->athlete[i].score = 1;break; } } if ( pfirst->athlete[i].item <=msp ) { pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score; } else { pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score; } } pfirst->totalscore = pfirst->menscore + pfirst->womenscore; pfirst = pfirst->next; } } void output() { pfirst = head->next; psecond = head->next; while ( pfirst->next != NULL ) { // clrscr(); printf("\n第%d號學校的結果成績:",pfirst->serial); printf("\n\n項目的數目\t學校的名字\t分數"); for (i=1;i<=ntsp;i++) { for (j=1;j<=pfirst->count;j++) { if ( pfirst->athlete[j].item == i ) { printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break; } } } printf("\n\n\n\t\t\t\t\t\t按任意建 進入下一頁"); getchar(); pfirst = pfirst->next; } // clrscr(); printf("\n運動會結果:\n\n學校編號\t男運動員成績\t女運動員成績\t總分"); pfirst = head->next; while ( pfirst->next != NULL ) { printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore); pfirst = pfirst->next; } printf("\n\n\n\t\t\t\t\t\t\t按任意建結束"); getchar(); } void create() { pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct)); pfirst->next = head->next ; head->next = pfirst ; pfirst->count = 1; pfirst->menscore = 0; pfirst->womenscore = 0; pfirst->totalscore = 0; } void Save() {FILE *fp; if((fp = fopen("school.dat","wb"))==NULL) {printf("can't open school.dat\n"); fclose(fp); return; } fwrite(pfirst,sizeof(SCH),10,fp); fclose(fp); printf("文件已經成功保存\n"); } void main() { system("cls"); printf("\n\t\t\t 運動會分數統計\n"); printf("輸入學校數目 (x>= 5):"); scanf("%d",&nsc); printf("輸入男選手的項目(x<=20):"); scanf("%d",&msp); printf("輸入女選手項目(<=20):"); scanf("%d",&wsp); ntsp = msp + wsp; phead = (int *)calloc(ntsp,sizeof(int)); pafirst = phead; pasecond = phead; input(); calculate(); output(); Save(); }
標簽: 源代碼
上傳時間: 2016-12-28
上傳用戶:150501
#include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp; int time=0,i=0,j=0,add[80],k=0,m; char *ch, str[900]; m=strlen(pd); if((fp=fopen("haha.txt","r"))==NULL) { printf("Cannot open this file\n"); exit(0); } for(;!feof(fp);i++) { str[i]=fgetc(fp); if(tolower(str[i])==tolower(pd[k])) {k++; if(k==m) if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp)))) { time++; add[j]=i-m+1; j++; k=0; } else k=0; } } if(time) { printf("The time is:%d\n",time); printf("The adders is:\n"); for(i=0;i
標簽: 查詢學會少年宮
上傳時間: 2016-12-29
上傳用戶:767483511
#include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp; int time=0,i=0,j=0,add[80],k=0,m; char *ch, str[900]; m=strlen(pd); if((fp=fopen("haha.txt","r"))==NULL) { printf("Cannot open this file\n"); exit(0); } for(;!feof(fp);i++) { str[i]=fgetc(fp); if(tolower(str[i])==tolower(pd[k])) {k++; if(k==m) if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp)))) { time++; add[j]=i-m+1; j++; k=0; } else k=0; } } if(time) { printf("The time is:%d\n",time); printf("The adders is:\n"); for(i=0;i<j;i++) printf("%5d",add[i]); if(i%5==0) printf("\n"); getch(); fclose(fp); } else printf("Sorry!Cannot find the word(^_^)"); } main() { char pd[10],choose='y'; int flag=1; while(flag) {printf("In put the word you want to seqarch:"); scanf("%s",pd); search(strlwr(pd)); printf("\nWould you want to continue?(Y/N):"); getchar(); scanf("%c",&choose); if((tolower(choose))=='n') flag=0; else flag=1; } printf("Thanks for your using!Bye-bye!\n"); getch(); }
標簽: 學生專用
上傳時間: 2016-12-29
上傳用戶:767483511
1.Describe a Θ(n lg n)-time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. (Implement exercise 2.3-7.) #include<stdio.h> #include<stdlib.h> void merge(int arr[],int low,int mid,int high){ int i,k; int *tmp=(int*)malloc((high-low+1)*sizeof(int)); int left_low=low; int left_high=mid; int right_low=mid+1; int right_high=high; for(k=0;left_low<=left_high&&right_low<=right_high;k++) { if(arr[left_low]<=arr[right_low]){ tmp[k]=arr[left_low++]; } else{ tmp[k]=arr[right_low++]; } } if(left_low<=left_high){ for(i=left_low;i<=left_high;i++){ tmp[k++]=arr[i]; } } if(right_low<=right_high){ for(i=right_low;i<=right_high;i++) tmp[k++]=arr[i]; } for(i=0;i<high-low+1;i++) arr[low+i]=tmp[i]; } void merge_sort(int a[],int p,int r){ int q; if(p<r){ q=(p+r)/2; merge_sort(a,p,q); merge_sort(a,q+1,r); merge(a,p,q,r); } } int main(){ int a[8]={3,5,8,6,4,1,1}; int i,j; int x=10; merge_sort(a,0,6); printf("after Merging-Sort:\n"); for(i=0;i<7;i++){ printf("%d",a[i]); } printf("\n"); i=0;j=6; do{ if(a[i]+a[j]==x){ printf("exist"); break; } if(a[i]+a[j]>x) j--; if(a[i]+a[j]<x) i++; }while(i<=j); if(i>j) printf("not exist"); system("pause"); return 0; }
上傳時間: 2017-04-01
上傳用戶:糖兒水嘻嘻
/*================================================================= 4掃16*16下入上出C語言程序, 低位起筆,數據反相。 預定義 **************************************************************/ #include #include //可使用其中定義的宏來訪問絕對地址? bit ture=1; // 使能正反相位選擇 bit false=0; // 使能反相 sbit SCK=P3^6; // EQU 0B6H ; 移位 sbit RCK=P3^5; //EQU 0B5H ; 并行鎖存 //sbit P1_3=P1^3; //外RAM擴展讀寫控制,不能重復申明 sbit EN1=P1^7; //BIT sbit FB=0xD8; // FB作為標志 sfr BUS_SPEED=0xA1; //訪問片外RAM速度設置寄存器 sfr P4SW=0xBB; //P4SW寄存器設置P4.4,P4.5,P4.6的功能 sfr P4=0xC0; // P4 EQU 0C0H sbit NC=P4^4; sbit CS=P4^6; //片選 sfr WDT_CONTR=0xC1; // 0C1H ;看門狗寄存器 sfr AUXR=0x8E; // EQU 08EH ;附件功能控制寄存器 sfr16 DPTR=0x82; sfr CLK_DIV=0x97 ; //時鐘分頻寄存器 const unsigned int code All_zk =256 ; // 0E11H ;原數據總字節 const unsigned int code am_zk =128 ; // 0E13H ;單幕數據量 const unsigned char code asp = 255; // asp數據相位字,如果是正相字,那么asp=0 bit basp=1; // asp數據相位字標記,如果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0xBD,0xBD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xB7,0x2B,0xAB,0xDE,0xF7,0xDD,0xFB,0xFB,0x5B,0xC3,0xF7,0xEB,0xD0,0xEE,0xEF, 0xFF,0xFD,0xFD,0xF8,0xFF,0xBD,0xE1,0xC0,0xFF,0xBD,0xBD,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xD3,0xED,0xC7,0xFF,0xF7,0xDC,0xFB,0xFF,0xDB,0xD9,0xF7,0xF7,0xDF,0xC0,0xEE}; const unsigned char data xzL_data =0x08; //0603H;一幕一行字節數 const unsigned int data aL_data =0x20; //單幕單號線(單組線)數據量 const unsigned char data mov =0x03A ; //移動速度 const unsigned int data t_T =0x040A ; //0E0AH ; 05FAH; ;停留時間 const unsigned char data mu_num=0x02 ; //0602H ;幕數 unsigned int m; //m幕長變量<=am_zk unsigned char data_z; //數據寄存器 unsigned int xd; //數據指針寄存器 /*********************************************************************** 數據轉移子函數 ===============================================================*/ char MOVD() { unsigned char f,nm; //nm幕數控制 unsigned char code *dptr; unsigned char xdata *xdptr = 0; f = asp ; for (m=0; m
上傳時間: 2017-05-04
上傳用戶:sbfd010
問題描述:以一個m*n的長方陣表示迷宮,0和1分別表示迷宮中的通路和障礙。設計一個程序,對任意設定的迷宮,求出一條從入口到出口的通路,或得出沒有通路的結論。 1.基本要求 (1)首先實現一個以鏈表作存儲結構的棧類型,然后編寫一個求解迷宮的非遞歸程序。求得的通路以三元組(i,j,d)的形式輸出。其中:(i,j)指示迷宮中的一個坐標,d表示走到下一坐標的方向。如下圖所示迷宮。從入口(1,1)到出口(8,8)的求解結果如下: (1,1)(1,2),(2,2)(3,2)(3,1)(4,1)(5,1)(5,2)(5,3)(6,3)(6,4)(6,5)(5,5)(4,5)(4,6)(4,7)(3,7)(3,8)(4,8)(5,8)(6,8)(7,8)(8,8) (2)以方陣形式輸出迷宮及其通路。 2.重點、難點 重點:針對迷宮問題的特點,利用棧的后進先出特點,選擇適當的數據結構。 難點:遞歸算法的設計與求解。
標簽: 迷宮
上傳時間: 2018-07-03
上傳用戶:MOOMWHITE
設有n=2k個運動員要進行網球循環賽。現要設計一個滿足以下要求的比賽日程表:⑴每個選手必須與其他n-1個選手各賽一次;⑵每個選手一天只能賽一次;⑶循環賽一共進行n-1天。按此要求可將比賽日程表設計-成有n行和n-l列的一個表。在表中第i行和第j列處填入第i個選手在第j天所遇到的選手。用分治法編寫為該循環賽設計一張比賽日程表的算法并運行實現、對復雜度進行分析。
上傳時間: 2019-06-04
上傳用戶:594551562
# include<stdio.h> # include<math.h> # define N 3 main(){ float NF2(float *x,float *y); float A[N][N]={{10,-1,-2},{-1,10,-2},{-1,-1,5}}; float b[N]={7.2,8.3,4.2},sum=0; float x[N]= {0,0,0},y[N]={0},x0[N]={}; int i,j,n=0; for(i=0;i<N;i++) { x[i]=x0[i]; } for(n=0;;n++){ //計算下一個值 for(i=0;i<N;i++){ sum=0; for(j=0;j<N;j++){ if(j!=i){ sum=sum+A[i][j]*x[j]; } } y[i]=(1/A[i][i])*(b[i]-sum); //sum=0; } //判斷誤差大小 if(NF2(x,y)>0.01){ for(i=0;i<N;i++){ x[i]=y[i]; } } else break; } printf("經過%d次雅可比迭代解出方程組的解:\n",n+1); for(i=0;i<N;i++){ printf("%f ",y[i]); } } //求兩個向量差的二范數函數 float NF2(float *x,float *y){ int i; float z,sum1=0; for(i=0;i<N;i++){ sum1=sum1+pow(y[i]-x[i],2); } z=sqrt(sum1); return z; }
上傳時間: 2019-10-13
上傳用戶:大萌萌撒