刘卫国matlab实验,MATLAB 程序设计与应用(刘卫国版)习题答案5

function p = excise0501(x1,x2)

x1=-1:0.01:1;

x2=-1:0.01:1; %[X,Y]=meshgrid(x1,x2);

for i=1:201

for j=1:201

if x1(i)+x2(j)> 1.0,

p(i,j)=0.5457*exp(-0.75*x2(j)^2-3.75*x1(i)^2-x1(i)*1.5);

elseif x1(i)+x2(j)<= 1.0

& x1(i)+x2(j)> -1.0,

p(i,j)=0.7575*exp(-x2(j)^2-6.0*x1(i));

elseif x1(i)+x2(j)<= -1.0,

p(i,j)=0.5457*exp(-0.75*x2(j)^2-3.75*x1(i)^2+x1(i)*1.5);

end

end

end

surf(x1,x2,p);

2.function Fibonacci1

a(1)=1; a(2)=1; i=2;

while i< 20

a(i+1)=a(i-1)+a(i);

i=i+1;

end

i, a,

3.function S = excise0503(a,b)

a=0.0;b=1.0;

dx = linspace(a,b,1001);

h=(a+b)/1000;

S=0.0;

for i= 1:1000

S = S +(sin(dx(i))+sin(dx(i+1)))*h/2;

end

S

4.function f = excise0504(x)

if nargin == 0, x=0.5;end;

if abs(x) >=1

break

end

f=x;

k=1;

u=1;

while norm(u,1) > 0

u=factorial(2*k)*x^(2*k+1)/(2^(2*k)*factorial(k)^2*(2*k+1));

f=f+u;

k=k+1;

end

f

5.function n = excise0505

n=1;m=1;

for i=2:1:9

if

mod(i,2)~=0

m=i;

n=[n,m];

end

end

[x,y]= size(n);

n=n(2:y);

%n;

for i=10:1:99

m=fix(i/10)+mod(i,10);

if

mod(m,2)~=0

n=[n,i];

end

end

%n;

for i=100:1:999

m=fix(i/100)+fix(mod(i,100)/10)+mod(i,10);

if

mod(m,2)~=0

n=[n,i];

end

end

%n;

m=fix(sqrt(999));

[x,y]= size(n);

for i=1:y

for j =

2:m

if mod(n(i),j) == 0 & j~= n(i)

n(i)=2;

end

end

end

p=1;

for i=1:y

if

n(i)~=2

p=[p,n(i)];

end

end

n=p;

[x,y]= size(n);

n=n(2:y);

n

6.

function excise0506

n=input('Please input n=');

W=[2 3 2 4 2 5];

for i=1:n

student(i).geometry=input('Please input geometry=');

student(i).math=input('Please input math=');

student(i).physics=input('Please input physics=');

student(i).english=input('Please input english=');

student(i).chinese=input('Please input chinese=');

student(i).chemistry=input('Please input chemistry=');

student(i).total=student(i).geometry*W(1)+student(i).math*W(2)...

+student(i).physics*W(3)+student(i).english*W(4)...

+student(i).chinese*W(5)+student(i).chemistry*W(6);

student(i).total=student(i).total/6

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值