您当前的位置: 首页 >  matlab

川川菜鸟

暂无认证

  • 2浏览

    0关注

    969博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

matlab刷题,由浅入深(1)

川川菜鸟 发布时间:2021-09-08 21:05:35 ,浏览量:2

文章目录
    • 前言
    • 简单的乘法
    • 三角形数
    • 删除列

前言

我是由浅入深的刷题,所有题目就在这一篇文章,我写一个题编辑发布一次,如果你正在看我可能还没来得及更新,还请见谅,我今晚一定出完。

简单的乘法

x 作为您的输入,将其乘以 2 并将结果放入 y。 例如: 在这里插入图片描述 我的代码: times2.m

function y = times2(x) % Do not edit this line.

  % Modify the line below so that the output y is twice the incoming value x

  y = 2.*x;

  % After you modify the code, press the "Submit" button, and you're on your way.

end % Do not edit this line.

调用测试: 在这里插入图片描述 注意点:乘法要用点乘

三角形数

三角形数:比如6=1+2+3就是三角形数。 显示三角形为: 在这里插入图片描述 所以题目为:输入四,返回10 在这里插入图片描述 代码为: triangle.m

function t = triangle(n)
t=0;
for a=1:n
    t=t+a;
end
end

测试: 在这里插入图片描述 考点:主要是一个for循环。

删除列

从输入矩阵A中删除第n列并在输出B中返回结果矩阵。 例如: 在这里插入图片描述 代码: 创建函数column_remova.m

function B = column_removal(A,n)
    A(:,n)=[];
  B = A;
end

测试: 在这里插入图片描述 知识点:

删除列用A(:,n)=[];
删除行用A(n,:)=[];
关注
打赏
1665165634
查看更多评论
立即登录/注册

微信扫码登录

0.0622s