西安交大并行计算作业Word下载.docx

上传人:b****5 文档编号:19932711 上传时间:2023-01-12 格式:DOCX 页数:15 大小:304.17KB
下载 相关 举报
西安交大并行计算作业Word下载.docx_第1页
第1页 / 共15页
西安交大并行计算作业Word下载.docx_第2页
第2页 / 共15页
西安交大并行计算作业Word下载.docx_第3页
第3页 / 共15页
西安交大并行计算作业Word下载.docx_第4页
第4页 / 共15页
西安交大并行计算作业Word下载.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

西安交大并行计算作业Word下载.docx

《西安交大并行计算作业Word下载.docx》由会员分享,可在线阅读,更多相关《西安交大并行计算作业Word下载.docx(15页珍藏版)》请在冰豆网上搜索。

西安交大并行计算作业Word下载.docx

,b,'

)'

Loop1:

dowhile((abs(f(a)-f(b)).gt.10e-6).and.

$(abs(a-b).gt.10e-6))

c=(a+b)/2

if(f(a)*f(c).le.0)then

b=c

else

a=c

endif

enddoLoop1

write(*,*)'

x='

c

else

Pleaseinputrealinterval'

end

realfunctionf(x)

f=4.1*x**3-5.3*x-11.8

end

结果:

1.4节作业

1.采样简单离散求和法求下面积分值:

read(*,*)a,b,n

h=(b-a)/(2.0*n)

s=0.0

x=a+h

f2=0.0

f4=0.0

loop1:

doi=1,n-1

x=x+h

f2=f2+f(x)

f4=f4+f(x)

enddoloop1

s=h/3.0*(f(a)+f(b)+4.0*f4+2.0*f2)

write(*,150)s

100format(1x,'

a='

f8.2,2x,'

b='

f8.2,

$2x,'

n='

i4)

150format(1x,'

s='

f16.7)

realfunctionf(x)

f=x**2/(sin(x)+1)

doubleprecisioni,ai,y

doubleprecisionsum=0

i=1

do10while(1/i.gt.1e-5)

sum=1/i+sum

i=i+1

10continue

write(*,*)'

sum='

sum

1.6节作业

1.调试课本中的所有程序;

(结果略)

2.用双精度型数据计算:

直到

代码:

10continue

结果:

3.已知三角形三个顶点的坐标分别为A(1.5,2.5),B(-2.5,1),C(1,-1),采用复型数据类型求三角形的面积和重心。

complexa,b,c,center,area,perimeter

a=(1.5,2.5)

b=(-2.5,1)

c=(1,-1)

center=(a+b+c)/3

perimeter=(a+b+c)/2

area=sqrt(perimeter*(perimeter-a)*(perimeter-b)*

$(perimeter-c))

write(*,10)"

center="

center

area="

area

10format(1x,a,f6.3,f6.3)

End

4.尝试编写课件例子中对应的破译程序。

有兴趣可以尝试修改原编码程序中后移位数(当前为5)变化的情况,比如移动位数为当前位置序号。

programmain

character*80line1,line2

characterl1

read(*,*)line1

n=len(line1)

do10i=1,n

l1=line1(i:

i)

if((lge(l1,'

A'

).and.lle(l1,'

Z'

)).or.

$(lge(l1,'

a'

z'

)))then

m=ichar(l1)+i

if((m.ge.ichar('

).and.m.le.ichar('

$(m.ge.ichar('

)))then

m=m-26

endif

line2(i:

i)=char(m)

i)=l1

write(*,*)line2

代码

1.7节作业

1.调试课件中的所有程序;

2.自由落体位移公式为:

其中

其中

是初始位置,

是初始速度,

为重力加速度,

为经历时间,编写一段程序根据时间值求位移

=1.2m,

=2.5m/s

(用格式输入语句读入t,并格式输出结果。

代码:

programmain

realt

write(*,*)"

Pleaseinputthetime"

read(*,*)t

callsum(t,s)

time="

t

displacement="

s

10format(1x,a,f10.2)

subroutinesum(t0,s)

realt0,s,s0,v0,g

s0=1.2

v0=2.5

g=9.8

s=(g*t0**2)/2+v0*t0+s0

1.8节作业

1.采用三种方法(矩形法、梯形法和Simpson法)编程对进行积分,积分上下限等参数需通过read语句从外部调入,并最终比较三种方法与理论解进行比较;

C矩阵法

realerror

read(*,*)a,b,n

x=a

h=(b-a)/n

f0=x*sin(x)

si=f0*h

s=s+si

write(*,100)a,b,n

write(*,200)s

f10.3,3x,'

$f10.3,3x,'

200format(1x,'

f15.8)

error=sin(b)-sin(a)-b*cos(b)+a*cos(a)-s

write(*,300)error

300format(1x,'

error='

f16.10)

C梯形法

si=((x+(i-1)*h)*sin(x+(i-1)*h)+

$(x+(i-1)*h)*sin(x+i*h))*h/2.0

f10.3,3x,

$'

Csinpson法

realerror

fa=fun(a)

fb=fun(b)

f4=fun(x)

do10i=1,n-1

f2=f2+fun(x)

f4=f4+fun(x)

s=h/3.0*(fa+fb+4.0*f4+2.0*f2)

$2x,'

write(*,200)error

realfunctionfun(x)

fun=x*sin(x)

矩阵法结果:

梯形法结果:

Sinpson法结果:

分析:

从上面得到的结果可以看出矩阵法误差最大,sinpson法次之,梯形法最优,但是从数学上分析,Sinpson法应得到最好的结果,在本题中误差较小,在可以接受的误差范围之内,如果遇到变化较大的函数进行积分,可以预见的是,sinpson法最优,梯形法次之,矩形法误差最大。

3.编程对任意系数一元多次方程

进行求根,求根范围和方程系数通过read语句从外部调入(采用一种方法即可,注意无根的处理);

代码:

programmain

5read(*,*)x1,x2,a1,a2,a3,a4

f1=a1*x1**3+a2*x1**2+a3*x1+a4

f2=a1*x2**3+a2*x2**2+a3*x2+a4

if(sign(f1,f2).eq.f1)goto5

f=1.0

20if((abs(x1-x2).gt.1e-5).and.

$abs(f).gt.1e-6)then

x=x2-(x2-x1)/(f2-f1)*f2

f=a1*x**3+a2*x**2+a3*x+a4

if(sign(f,f1).eq.f)then

x1=x

f1=f

x2=x

f2=f

goto20

if(abs(f).gt.1e-6)x=(x1+x2)/2.0

write(*,100)x

f15.7)

4.改编课件中求函数极值程序,实现最大值的求解,函数为:

reallow,high,x1,x2

read(*,*)low,high

write(*,200)

x1=low+0.618*(high-low)

x2=high-0.618*(high-low)

10if(high-low.gt.1e-4)then

f1=3*x1*x1-8.0*x1-7.0

f2=3*x2*x2-8.0*x2-7.0

write(*,202)x1,f1,x2,f2

if(f1.gt.f2)then

high=x1

x1=x2

low=x2

x2=x1

goto10

f=f2

x=x2

f=f1

x=x1

write(*,204)x,f

200format(12x,'

x1'

14x,'

f1'

$13x,'

x2'

13x,'

f2'

/)

202format(1x,4f15.7)

204format('

0'

f10.6,5x,

f(x)='

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1