今日学习之matlab

Problem 2020. Area of an Isoceles Triangle

function A = isocelesArea(x,y)
a=sqrt(1-(y/(2*x))^2)  
A = 0.5*x*y*a
end

Problem 2023. Is this triangle right-angled?

function flag = isRightAngled(a,b,c)
x=[a b c];
y=sort(x);
a=y(1);b=y(2);c=y(3);
if any(a^2+b^2==c^2)
   flag = true;
else
flag = false;
end
end

Problem 2024. Triangle sequence

function area = triangle_sequence(n)
x=9;
y=16;
z=25;
area=0;
for i=1:n
    if i==1
    area=x+y;
    elseif i==2
    z=area;
    area=y+z;
    else   
    y=z;
    z=area;
    area=y+z;    
    end
end
end

Problem 2016. Area of an equilateral triangle

function y = equilateral_area(x)
  y = sqrt(3)*x^2/4; 
end

Problem 2017. Side of an equilateral triangle

function x = side_length(A)
  x = sqrt(A*4/sqrt(3)); 
end

Problem 2018. Side of a rhombus

function y = rhombus_side(x)
  y = sqrt(x^2+(x+1)^2)/2;
end

Problem 1974. Length of a short side

function a = calculate_short_side(b, c)
  a = sqrt(c^2-b^2);
end

Problem 641. Make a random, non-repeating vector.

function vec = makeRandomOrdering(n)
  vec = randperm(n);
end

Problem 568. Number of 1s in a binary string

function y = one(x)
  y=0;
for i=1:length(x)
    if str2num(x(i))==1
        y=y+1;
    else
        y=y;
    end
end
end

Problem 649. Return the first and last characters of a character array

function y = stringfirstandlast(x)
  if length(x)==1
    y=[x(1) x(1)];
else
    y=[x(1) x(end)];
  end
end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值