In: Mechanical Engineering
1. A square-based pyramid has the volume V. If the vertical height is H (the normal distance from the square base to the point), write a MATLAB function that:
has V and H as input arguments
calculates the length of the side of the square (S)
has S as an output argument
Write MATLAB code that tests the function for the values:
V = 10 m3 and H = 2 m.
V = 2.586×106 m3 and H = 146.6 m (the original dimensions of the Great Pyramid of Giza).
2. Repeat SPIDER 2 Q1, but write a function that accepts a year as an input argument and determines whether that year is a leap year. The output should be the variable extra_day, which should be 1 if the year is a leap year and 0 otherwise.
You must write a script file that thoroughly tests whether your function works correctly.
% Matlab script to test the computation of length of a side of a
square
% for given Volume of pyramid and its height
clc;
% test-1
V=10;
H=2;
S=lengthOfSideofSquare(V,H);
fprintf('\nfor volume %f, Height %f,Length of side of square is :
%f',V,H,S);
% test-2
V=2.586*(10^6);
H=146.6;
S=lengthOfSideofSquare(V,H);
fprintf('\nfor volume %f, Height %f,Length of side of square is :
%f',V,H,S);
%--------------------------------------------------------
%function file: lengthOfSideofSquare.m
function S= lengthOfSideofSquare(V,H)
% lengthOfSideofSquare accepts Volume and height of a square
based
% Pyramid and returns length of a side of the square
S=sqrt((3*V)/H);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%output:
QUESTION NO-2
As details od Spider 2 Q-1 is not supplied , I sen here only the part you want to enhance.i,e test of an extra day.
% SCRIPT FILE:
% Script file to test a year contains an extra day(leap
year)
clc;
year=2016;
extra_day=isLeapYear(year)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Function file : isLeapYear.m
function extra_day = isLeapYear(year)
% isLeapYear(year) returns 1 if year is a leap, 0 otherwise
if ( mod(year,4) ==0 && mod(year,100) ~=0) ||
mod(year,400)==0
extra_day=1;
else
extra_day=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%
%Output