| 4 | 1/1 | 返回列表 |
| 查看: 821 | 回復: 3 | ||
caoweiyue新蟲 (小有名氣)
|
[求助]
剛開始學Fortran 幫忙看一下這個程序 為什么算不出結(jié)果
|
|
下面的程序算的是全選主元的高斯消去法, 我是照徐士良的算法集編的,但是結(jié)果都是0 program main implicit none integer::i,L integer,parameter::n=4 real::A(n,n),b(n),x(n) data A / 0.2368,0.1968,0.1582,1.1161,0.2471,0.2071,1.1675,0.1254,& &0.2568,1.2168,0.1768,0.1397,1.2671,0.2271,0.1871,0.1490 / data b / 1.8471,1.7471,1.6471,1.5471 / call agaus(A,b,n,L) if(L==0) then write(*,*) "fail" else do i=1,n write(*,"('x',i1,'=',f6.4)" i,x(i)end do end if stop end program subroutine agaus(A,b,n,L) implicit none integer:: i,j,k,n,is,js,L real:: D, T real:: A(n,n),b(n),x(n) L=1 do k=1,n-1 D=0.0 !選出了最大的,并保存其位置 do i=k,n do j=k,n if( abs(A(i,j))>D ) then D=A(i,j) is=i js=j end if end do end do if(D+1.0==1.0) then L=0 return end if !列交換 if(js/=k) then do i=1,n T=A(i,k) A(i,k)=A(i,js) A(i,js)=T end do end if !行交換 if(is/=k) then do j=k,n T=A(k,j) A(k,j)=A(is,j) A(is,j)=A(k,j) end do T=b(k) b(k)=b(is) b(is)=b(k) end if !化成三角矩陣 do i=k+1,n do j=k,n A(i,j)=A(i,j)-A(i,k)/A(k,k)*A(k,j) end do b(i)=b(i)-A(i,k)/A(k,k)*b(k) end do end do if(A(n,n)+1.0==1.0) then L=0 return end if !回代 x(n)=b(n)/A(n,n) do i=n-1,1,-1 T=0.0 do j=i+1,n T=T+A(i,j)*x(j) end do x(i)=(b(i)-T)/A(i,i) end do return end subroutine agaus |
至尊木蟲 (知名作家)
中央書籍處書記

鐵蟲 (初入文壇)

新蟲 (初入文壇)
| 4 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 286求調(diào)劑 +8 | Faune 2026-03-21 | 8/400 |
|
|---|---|---|---|---|
|
[基金申請]
學校已經(jīng)提交到NSFC,還能修改嗎?
40+4
|
babangida 2026-03-19 | 9/450 |
|
|
[考研] 一志愿西安交通大學材料工程專業(yè) 282分求調(diào)劑 +8 | 楓橋ZL 2026-03-18 | 10/500 |
|
|
[考研] 南昌大學材料專碩311分求調(diào)劑 +6 | 77chaselx 2026-03-20 | 6/300 |
|
|
[考研] 材料工程(專)一志愿985 初試335求調(diào)劑 +3 | hiloiy 2026-03-17 | 4/200 |
|
|
[考研] 求調(diào)劑 +3 | Ma_xt 2026-03-17 | 3/150 |
|
|
[考研] 274求調(diào)劑 +10 | S.H1 2026-03-18 | 10/500 |
|
|
[考研]
|
然11 2026-03-19 | 4/200 |
|
|
[考研] 北科281學碩材料求調(diào)劑 +5 | tcxiaoxx 2026-03-20 | 5/250 |
|
|
[考研] 一志愿華中農(nóng)業(yè)071010,總分320求調(diào)劑 +3 | 困困困困坤坤 2026-03-20 | 3/150 |
|
|
[考研] 319求調(diào)劑 +3 | 小力氣珂珂 2026-03-20 | 3/150 |
|
|
[考研] 一志愿吉林大學材料學碩321求調(diào)劑 +11 | Ymlll 2026-03-18 | 15/750 |
|
|
[考研] 求調(diào)劑 +3 | @taotao 2026-03-20 | 3/150 |
|
|
[考博] 申博26年 +3 | 八6八68 2026-03-19 | 3/150 |
|
|
[考研] 311求調(diào)劑 +11 | 冬十三 2026-03-15 | 12/600 |
|
|
[考研] 326求調(diào)劑 +5 | 上岸的小葡 2026-03-15 | 6/300 |
|
|
[考博] 26申博 +4 | 八6八68 2026-03-16 | 4/200 |
|
|
[考研] 283求調(diào)劑 +3 | 聽風就是雨; 2026-03-16 | 3/150 |
|
|
[考研] 中科院材料273求調(diào)劑 +4 | yzydy 2026-03-15 | 4/200 |
|
|
[考研] 本科南京大學一志愿川大藥學327 +3 | 麥田耕者 2026-03-14 | 3/150 |
|