资源描述:
《数学建模数模第一次作业(章绍辉版).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.(1)n=101;x1=linspace(-1,1,n);x2=linspace(-2,2,n);y1=[sqrt(1-x1.^2);-sqrt(1-x1.^2)];y2=[sqrt(4-x2.^2);-sqrt(4-x2.^2);sqrt(1-(x2.^2)/4);-sqrt(1-(x2.^2)/4)];plot(x1,y1)holdon;plot(x2,y2)title('椭圆x^2/4+y^2=1的内切圆和外切圆')axisequal(2)x1=linspace(-2,2,101);x2=linspace(-2,8);axiseq
2、ualplot(exp(x1),x1,x1,exp(x1),x2,x2)title('指数函数y=exp(x)和对数函数y=ln(x)关于y=x对称')(3)holdonq=input('请输入一个正整数q;')fori=1:qforj=1:iifrem(j,i)plot(j/i,1/i)endendend3.代码如下:n=input('请输入实验次数n=')k=0;fori=1:nx=ceil(rand*6)+ceil(rand*6);ifx==3
3、x==11k=k+1;elseifx~=2&x~=7&x~=12y=ceil(rand*6
4、)+ceil(rand*6);whiley~=x&y~=7y=ceil(rand*6)+ceil(rand*6);endify==7k=k+1;endendend更改试验次数n的值,打赌者赢得概率w随n的变化情况如下:试验次数n打赌者赢得概率w10000.528015000.495320000.499225000.515730000.501135000.511540000.511745000.511050000.5041从上表可看出打赌者赢的概率大约为0.5110。理论计算:掷一次骰子,得到点数及相应的概率点数23456789101112概
5、率p1/362/363/364/365/366/365/364/363/362/361/36打赌者赢的情况有两种:(1)第一次就掷出3点或者11点;其概率P1=2/36+2/36=1/9;(2)当第1次掷出的点数之和是4,5,6,8,9或10,,继续掷骰子,直到掷出的点数之和是7或原来的值为止,先得到的点数之和是7;其概率P2=196/495则打赌者赢的概率P=P1+P2=0.50707.4.(1)(i)输入代码:f=@(r,t)3.9*exp(r.*(t-1790));t=1790:10:2000;c=[3.9,5.3,7.2,9.6,1
6、2.9,17.1,23.2,31.4,38.6,50.2,62.9,76.0,92.0,106.5,123.2,131.7,150.7,179.3,204.0,226.5,251.4,281.4];r0=0.036;r=nlinfit(t,c,f,r0)sse=sum((c-f(r,t)).^2)得到:r=0.02119sse=17418.48(ii)输入代码:f=@(k,t)k(1)*exp(k(2).*(t-1790));k0=[3.9,0.036];k=nlinfit(t,c,f,k0)sse=sum((c-f(k,t)).^2)得到
7、:k=14.993959233344270.01422307528878sse=2.263917490357360e+003即:x0=14.994r=0.014223sse=2263.92(iii)输入代码:f=@(k,t)k(1)*exp(k(2).*(t-k(3)));k0=[3.9,0.036,1790];k=nlinfit(t,c,f,k0)sse=sum((c-f(k,t)).^2)得到:k=1.0e+003*0.007529449634170.000014223084281.74157000966658sse=2.2639174
8、90325156e+003即:x0=7.52945r=0.014223t0=1741.57sse=2263.92从误差平方和sse来看(ii)和(iii)的拟合效果较好。(2)对两边取对数得令y=,x=t-1790,A=r,B=,则原方程变为:y=Ax+B。用polyfit拟合参数A、B,代码如下:t=1790:10:2000;c=[3.9,5.3,7.2,9.6,12.9,17.1,23.2,31.4,38.6,50.2,62.9,76.0,92.0,106.5,123.2,131.7,150.7,179.3,204.0,226.5,25
9、1.4,281.4];x=t-1790;y=log(c);k=polyfit(x,y,1)r=k(1),x0=exp(k(2))sse=sum((c-exp(polyval(k,