MATLAB程序设计与应用刘卫国(第三版)课后实验答案——4

这篇博客详细介绍了MATLAB程序设计中如何运用函数与脚本文件,尤其针对线性代数问题。内容涵盖从基本的命名规则到具体的实例解析,包括多个部分的练习题解答,帮助读者掌握MATLAB在矩阵运算中的应用。
摘要由CSDN通过智能技术生成

MATLAB程序设计与应用刘卫国(第三版)课后实验答案——4

本节开始使用函数与脚本文件,命名规则为testx_x_x,自定义命名后命令行窗口执行时也须对应

function test4_1(x)
	if x<0&&x~=-3
   	y=x.*x+x-6;
   elseif (x>=0)&&(x<5)&&x~=2&&x~=3
       y=x.*x-5.*x+6;
   else
       y=x.*x-x-1;
  end
	sprintf('%0.1f',y)

在这里插入图片描述

score=input('score=');
if score<=100&&score>=90
   	sprintf('grade=A')
elseif score<90&&score>=80
   	sprintf('grade=B')
elseif score<80&&score>=70
   	sprintf('grade=C')
elseif score<70&&score>=60
   	sprintf('grade=D')
elseif score<60
   	sprintf('grade=E')
else
   	sprintf('错误,不合理,输入成绩无效!')
end

在这里插入图片描述

score=input('score=');
if score<=100&&score>=0
  switch fix(score/10)
      case {9,10}
          grade='A';
      case {8}
          grade='B';
      case {7}
          grade='C';
      case {6}
          grade='D';
      otherwise
          grade='E';
   	end
   	grade
else
   	disp('错误!输出成绩无效!');
end

在这里插入图片描述

time=input('time=');
switch time
   case {time>120}
      money=(time-120)*(1+15/100)*84+120*84
   case {time<60}
       money=time*84-700
   otherwise
       money=time*84
end

在这里插入图片描述

A=floor(rand(1)*90+10)
B=floor(rand(1)*90+10)
x=input('输入一个运算符:','s');
switch x
   case {'+'}
       c=A+B;
   case {'-'}
       c=A-B;
   case {'*'}
       c=A*B;
   case {'/'}
       c=A/B;
   otherwise
       c='false';
end
c

在这里插入图片描述

A=input('输入一个5*6矩阵A=');
n=input('输入一个正整数n=');
if n<5&&n>0
   disp(A(n,:));
else
  disp(A(5,:));
   disp('error:n>5')
end

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值