0
点赞
收藏
分享

微信扫一扫

今日学习之matlab

王传学 2022-04-14 阅读 64
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

举报

相关推荐

今日学习之Javascript

今日份学习

今日学习总结

今日学习打卡

今日cody之练习

今日学习总结2

0 条评论