#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
// 學生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person { char name[10]; int ID; int cj_yw; int cj_sx; struct person* next; struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
上傳時間: 2016-12-29
上傳用戶:767483511
// 學生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person { char name[10]; int ID; int cj_yw; int cj_sx; struct person* next; struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
標簽: 學生 計算器
上傳時間: 2016-12-29
上傳用戶:767483511
把代碼里的?替換為空格
上傳時間: 2017-11-01
上傳用戶:weiyi
是否要先打開ALLEGRO? 不需要(當然你的機器須有CADENCE系統)。生成完封裝后在你的輸出目錄下就會有幾千個器件(全部生成的話),默認輸出目錄為c:\MySym\. Level里面的Minimum, Nominal, Maximum 是什么意思? 對應ipc7351A的ABC封裝嗎? 是的 能否將MOST, NOMINAL, LEAST三種有差別的封裝在命名上也體現出差別? NOMINAL 的名稱最后沒有后綴,MOST的后綴自動添加“M”,LEAST的后綴自動添加“L”,你看看生成的庫名稱就知道了。(直插件以及特別的器件,如BGA等是沒有MOST和LEAST級別的,對這類器件只有NOMINAL) IC焊盤用長方形好像比用橢圓形的好,能不能生成長方形的? 嗯。。。。基本上應該是非直角的焊盤比矩形的焊盤好,我記不得是AMD還是NS還是AD公司專門有篇文檔討論了這個問題,如果沒有記錯的話至少有以下好處:信號質量好、更省空間(特別是緊密設計中)、更省錫量。我過去有一篇帖子有一個倒角焊盤的SKILL,用于晶振電路和高速器件(如DDR的濾波電容),原因是對寬度比較大的矩形用橢圓焊盤也不合適,這種情況下用自定義的矩形倒角焊盤就比較好了---你可以從網上另外一個DDR設計的例子中看到。 當然,我已經在程序中添加了一選擇項,對一些矩形焊盤可以選擇倒角方式. 剛才試了一下,感覺器件的命名的規范性不是太好,另好像不能生成器件的DEVICE文件,我沒RUN完。。。 這個程序的命名方法基本參照IPC-7351,每個人都有自己的命名嗜好,仍是不好統一的;我是比較懶的啦,所以就盡量靠近IPC-7351了。 至于DEVICE,的選項已經添加 (這就是批量程序的好處,代碼中加一行,重新生產的上千上萬個封裝就都有新東西了)。 你的庫都是"-"的,請問用過ALLEGRO的兄弟,你們的FOOTPRINT認"-"嗎?反正我的ALLEGRO只認"_"(下劃線) 用“-”應該沒有問題的,焊盤的命名我用的是"_"(這個一直沒改動過)。 部分絲印畫在焊盤上了。 絲印的問題我早已知道,只是盡量避免開(我有個可配置的SilkGap變量),不過工作量比較大,有些已經改過,有些還沒有;另外我沒有特別費功夫在絲印上的另一個原因是,我通常最后用AUTO-SILK的來合并相關的層,這樣既方便快捷也統一各個器件的絲印間距,用AUTO-SILK的話絲印線會自動避開SOLDER-MASK的。 點擊allegro后命令行出現E- Can't change to directory: Files\FPM,什么原因? 我想你一定是將FPM安裝在一個含空格的目錄里面了,比如C:\Program Files\等等之類,在自定義安裝目錄的時候該目錄名不能含有空格,且存放生成的封裝的目錄名也不能含有空格。你如果用默認安裝的話應該是不會有問題的, 默認FPM安裝在C:\FPM,默認存放封裝的目錄為C:\MYSYM 0.04版用spb15.51生成時.allegro會死機.以前版本的Allegro封裝生成器用spb15.51生成時沒有死機現象 我在生成MELF類封裝的時候有過一次死機現象,估計是文件操作錯誤導致ALLEGRO死機,原因是我沒有找到在skill里面直接生成SHAPE焊盤的方法(FLASH和常規焊盤沒問題), 查了下資料也沒有找到解決方法,所以只得在外部調用SCRIPT來將就一下了。(下次我再查查看),用SCRIPT的話文件訪問比較頻繁(幸好目前MELF類的器件不多). 解決辦法: 1、對MELF類器件單獨選擇生成,其它的應該可以一次生成。 2、試試最新的版本(當前0.05) 請說明運行在哪類器件的時候ALLEGRO出錯,如果不是在MELF附近的話,請告知,謝謝。 用FPM0.04生成的封裝好像文件都比較大,比如CAPC、RES等器件,都是300多K,而自己建的或采用PCB Libraries Eval生成的封裝一般才幾十K到100K左右,不知封裝是不是包含了更多的信息? 我的每個封裝文件包含了幾個文字層(REF,VAL,TOL,DEV,PARTNUMBER等),SILK和ASSEM也是分開的,BOND層和高度信息,還有些定位線(在DISP層),可能這些越來越豐富的信息加大了生成文件的尺寸.你如果想看有什么內容的話,打開所有層就看見了(或REPORT) 非常感謝 LiWenHui 發現的BUG, 已經找到原因,是下面這行: axlDBChangeDesignExtents( '((-1000 -1000) (1000 1000))) 有尺寸空間開得太大,后又沒有壓縮的原因,現在生成的封裝也只有幾十K了,0.05版已經修復這個BUG了。 Allegro封裝生成器0.04生成do-27封裝不正確,生成封裝的焊盤的位號為a,c.應該是A,B或者1,2才對. 呵呵,DIODE通常管腳名為AC(A = anode, C = cathode) 也有用AK 或 12的, 極少見AB。 除了DIODE和極個別插件以及BGA外,焊盤名字以數字為主, 下次我給DIODE一個選擇項,可以選擇AC 或 12 或 AK, 至于TRANSISTER我就不去區分BCE/CBE/ECB/EBC/GDS/GSD/DSG/DGS/SGD/SDG等了,這樣會沒完沒了的,我將對TRANSISTER強制統一以數字編號了,如果用家非要改變,只得在生成庫后手工修改。
標簽: Footprint Maker 0.08 FPM skill
上傳時間: 2018-01-10
上傳用戶:digitzing
CMMI漢化版,大家多交流,非常給力,希望能給大家帶來幫助!
標簽: Simplified-Chinese-FINAL CMMI-DEV-v 1.3
上傳時間: 2018-04-18
上傳用戶:aolufeiyfz
#include <stdio.h> #include <stdlib.h> ///鏈式棧 typedef struct node { int data; struct node *next; }Node,*Linklist; Linklist Createlist() { Linklist p; Linklist h; int data1; scanf("%d",&data1); if(data1 != 0) { h = (Node *)malloc(sizeof(Node)); h->data = data1; h->next = NULL; } else if(data1 == 0) return NULL; scanf("%d",&data1); while(data1 != 0) { p = (Node *)malloc(sizeof(Node)); p -> data = data1; p -> next = h; h = p; scanf("%d",&data1); } return h; } void Outputlist(Node *head) { Linklist p; p = head; while(p != NULL ) { printf("%d ",p->data); p = p->next; } printf("\n"); } void Freelist(Node *head) { Node *p; Node *q = NULL; p = head; while(p != NULL) { q = p; p = p->next; free(q); } } int main() { Node *head; head = Createlist(); Outputlist(head); Freelist(head); return 0; } 2.順序棧 [cpp] view plain copy #include <iostream> #include <stdio.h> #include <stdlib.h> ///順序棧 #define MaxSize 100 using namespace std; typedef
上傳時間: 2018-05-09
上傳用戶:123456..
網絡爬蟲 網絡爬蟲在CPP中爬行鏈接到你想要的深度??刂婆_應用程序 Ubuntu 14.04 LTS上編譯的程序 用g+編譯器編譯 相依性 卷曲 Boost圖書館 用于編譯的命令 G+爬蟲.cpp-lcurl-lost_regex-o爬蟲 輸入 URL:您想要抓取示例“dirghbuch.com”的URL 鏈接數:要從爬行中提取的每頁鏈接數 深度:我們想爬多深,在哪里深度可以定義為樹的深度。 輸出量 crawler.txt 限制 鏈接數最多可達100。 Does not work for website which has blocked curl crawling for example google.com yahoo.com 由于缺乏并行性,所以速度很慢。 沒有完整URL的鏈接被追加到用戶在大容量中插入的URLwww.xyz.com有/conatct-us的網址將是www.xyz.com/contact-us 唯一的單詞也包含html標記。 可能的改進,但尚未落實 限制共享變量的使用 改進使其易于并行化 比卷曲更有效的爬行方式
上傳時間: 2018-06-20
上傳用戶:1370893801
function [alpha,N,U]=youxianchafen2(r1,r2,up,under,num,deta) %[alpha,N,U]=youxianchafen2(a,r1,r2,up,under,num,deta) %該函數用有限差分法求解有兩種介質的正方形區域的二維拉普拉斯方程的數值解 %函數返回迭代因子、迭代次數以及迭代完成后所求區域內網格節點處的值 %a為正方形求解區域的邊長 %r1,r2分別表示兩種介質的電導率 %up,under分別為上下邊界值 %num表示將區域每邊的網格剖分個數 %deta為迭代過程中所允許的相對誤差限 n=num+1; %每邊節點數 U(n,n)=0; %節點處數值矩陣 N=0; %迭代次數初值 alpha=2/(1+sin(pi/num));%超松弛迭代因子 k=r1/r2; %兩介質電導率之比 U(1,1:n)=up; %求解區域上邊界第一類邊界條件 U(n,1:n)=under; %求解區域下邊界第一類邊界條件 U(2:num,1)=0;U(2:num,n)=0; for i=2:num U(i,2:num)=up-(up-under)/num*(i-1);%采用線性賦值對上下邊界之間的節點賦迭代初值 end G=1; while G>0 %迭代條件:不滿足相對誤差限要求的節點數目G不為零 Un=U; %完成第n次迭代后所有節點處的值 G=0; %每完成一次迭代將不滿足相對誤差限要求的節點數目歸零 for j=1:n for i=2:num U1=U(i,j); %第n次迭代時網格節點處的值 if j==1 %第n+1次迭代左邊界第二類邊界條件 U(i,j)=1/4*(2*U(i,j+1)+U(i-1,j)+U(i+1,j)); end if (j>1)&&(j U2=1/4*(U(i,j+1)+ U(i-1,j)+ U(i,j-1)+ U(i+1,j)); U(i,j)=U1+alpha*(U2-U1); %引入超松弛迭代因子后的網格節點處的值 end if i==n+1-j %第n+1次迭代兩介質分界面(與網格對角線重合)第二類邊界條件 U(i,j)=1/4*(2/(1+k)*(U(i,j+1)+U(i+1,j))+2*k/(1+k)*(U(i-1,j)+U(i,j-1))); end if j==n %第n+1次迭代右邊界第二類邊界條件 U(i,n)=1/4*(2*U(i,j-1)+U(i-1,j)+U(i+1,j)); end end end N=N+1 %顯示迭代次數 Un1=U; %完成第n+1次迭代后所有節點處的值 err=abs((Un1-Un)./Un1);%第n+1次迭代與第n次迭代所有節點值的相對誤差 err(1,1:n)=0; %上邊界節點相對誤差置零 err(n,1:n)=0; %下邊界節點相對誤差置零 G=sum(sum(err>deta))%顯示每次迭代后不滿足相對誤差限要求的節點數目G end
標簽: 有限差分
上傳時間: 2018-07-13
上傳用戶:Kemin
恩211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
上傳時間: 2019-01-22
上傳用戶:HsiuChi