数学实验4答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第四次练习题
1、 编程找出 5,1000+=≤b c c 的所有勾股数,并问:能否利用通项表示 },,{c b a ? >> for b=1: 995
a=sqrt((b+5)^2-b^2);
if(a==floor(a))
fprintf('a=%i,b=%i,c=%i\n',a,b,b+5)
end
end
a=15,b=20,c=25
a=25,b=60,c=65
a=35,b=120,c=125
a=45,b=200,c=205
a=55,b=300,c=305
a=65,b=420,c=425
a=75,b=560,c=565
a=85,b=720,c=725
a=95,b=900,c=905
>> for c=6:1000
a=sqrt(c^2-(c-5)^2);
if(a==floor(a))
fprintf('a=%i,b=%i,c=%i\n',a,c-5,c)
end
end
a=15,b=20,c=25
a=25,b=60,c=65
a=35,b=120,c=125
a=45,b=200,c=205
a=55,b=300,c=305
a=65,b=420,c=425
a=75,b=560,c=565
a=85,b=720,c=725
a=95,b=900,c=905
{a,b,c}={100*n^2-100*n+25,10*n^2-10*n,10*n^2-10*n+5}
2、编程找出不定方程 )35000(122<-=-y Dy x 的所有正整数解。(学号为单号的取D=2, 学号为双号的取D=5)
D=2(学号为单号)
>> for y=1:34999
x=sqrt(2*y^2-1);
if(x==floor(x))
fprintf('x=%i,y=%i\n',x,y)
end
end
x=1,y=1
x=7,y=5
x=41,y=29
x=239,y=169
x=1393,y=985
x=8119,y=5741
x=47321,y=33461
3、 设 ⎩⎨⎧==+=--1,12121a a ma
a a n n n , 编程计算.100a (学号为双号的取m=1)
输入:
clear all
clc
an1=1;an2=1;an=0;
for n=3:100
an=an1+an2;
an2=an1;
an1=an;
end
fprintf('N=%i,An=%i\n',n,an); 输出:
N=100,An=3.542248e+020
4、用Monte Carlo 方法计算圆周率π 输入:temp.m
clear all
clc
s=0;
for n=1:100000
r1=rand(1);
r2=rand(1);
if r1^2+r2^2<=1
s=s+1;
end
end
pi=4*s/n;
fprintf('Pi=%E',pi);
输出:
Pi=3.141600E+000
5、实验十练习7:选取10 000对随机的b a ,,根据1),(=b a 的概率求出π的近似值. 输入:temp.m
clear all
clc
s=0;
for n=1:10000.
a=ceil(rand(1)*10000);
b=ceil(rand(1)*10000);
p=a;q=b;
if(p r=p;p=q;q=r; end while q~=0 r=q;q=mod(p,q);p=r; end if p==1 s=s+1; end end pi=sqrt(6/(s/10000)); fprintf('Pi=%E',pi); 输出: Pi=3.146065E+000>> 2007,8.250000,40.875000 2008,8.375000,41.062500 2009,8.312500,40.968750 2010,8.343750,41.015625 2011,8.328125,40.992188 2012,8.335938,41.003906 2013,8.332031,40.998047 2014,8.333984,41.000977 2015,8.333008,40.999512 2016,8.333496,41.000244 2017,8.333252,40.999878 2018,8.333374,41.000061 2019,8.333313,40.999969 2020,8.333344,41.000015 2021,8.333328,40.999992 2022,8.333336,41.000004 2023,8.333332,40.999998 2024,8.333334,41.000001 2025,8.333333,41.000000 2026,8.333333,41.000000 2027,8.333333,41.000000 2028,8.333333,41.000000