MATLAB第二次作业(MATLAB基础与应用(第三版))

MATLAB第二次作业

题目

解答

1 、代码:

a1=2;a2=4;a3=7;a4=12;
subplot(221)
ezplot('x^2/2^2+y^2/(25-2^2)-1')
title('a=2')
grid on
subplot(222)
ezplot('x^2/4^2+y^2/(25-4^2)-1')
title('a=4')
grid on
subplot(223)
ezplot('x^2/(-3)^2+y^2/(25-(-3)^2)-1')
title('a=-3')
grid on
subplot(224)
ezplot('x^2/(-2.5)^2+y^2/(25-(-2.5)^2)-1')
title('a=-2.5')
grid on

 运行结果:

2、代码: 

clear;clc;
syms x y
x=0:0.2:5;
y=x.*exp(sin(x));
f=plot(x,y,'r--p');
set(f,'linewidth',4)
grid on
title('y=xe^s^i^n^x')
xlabel('x(0\rightarrow5)')
ylabel('y(0\rightarrow5)')

运行结果:

3、代码:

clear;clc;
[x,y]=meshgrid(-3:0.1:3,-3:0.1:3);
if x+y>1
    p=0.54*exp(-0.75*x.^2-3.75*y.^2-1.5*y);
elseif (-1<x+y)&(x+y<1)
    p=0.7575*exp(-x.^2-6*y.^2);
else
    p=0.5457*exp(-0.75*x.^2-3.75*y.^2+1.5*y);
end
surf(x,y,p)
axis([-3 3 -3 3 0 0.7])
xlabel('x');ylabel('y');zlabel('P(x,y)')
title('分段函数表示的曲面')

运行结果:

4、代码:

clear;clc;
prompt={'请输入圆的半径:'};
title='圆面积周长计算器';
def={'1'};
lineno=1;
answer=inputdlg(prompt,title,[1 45]);
f=str2num(answer{1});
s=pi*f^2;
c=2*pi*f;
string=['圆的面积为',num2str(s),'    圆的周长为',num2str(c)];
[IconData,IconCMap]=imread('handsome.jpg');
h=msgbox(string,'运行结果','custom',IconData,IconCMap);
set(h,'resize','on')

运行结果:

 取半径为13,得出结果

5、代码:

clear;clc;
f=@(t,y)[y(1)-0.01*y(1)*y(2);-y(2)+0.015*y(1)*y(2)];
tn=20;
y0=[25;30];
[t,y]=ode45(f,[0,tn],y0);
plot(t,y)
axis([0 20 0 350])
title('Lotka-Voltera模型')
ylabel('数量(y)');
xlabel('时间(t)');
h=legend('捕食者','被捕食者');
set(h,'Location','northeast')
set(gca,'xtick',0:2:20,'ytick',0:50:350)

运行结果:

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值