Question

In: Mechanical Engineering

Use Matlab to write the following 1. Write code to determine whether a year is a...

Use Matlab to write the following

1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows:

All years evenly divisible by 400 are leap years.

Years evenly divisible by 100, but not by 400, are not leap years.

Years divisible by 4, but not by 100, are leap years.

All other years are not leap years.

For example, the years 1800, 1900, 2100, 2300 and 2500 are not leap years, but 2400 is a leap year.

2. Solve the following:

a. Use a for loop to determine the sum of the first 10 terms in the series 5k3, where k=1,2,3,...,10. Report your answer to the Command Window.

b. Repeat part (a) without using a loop.

Solutions

Expert Solution

Problem 1

MatLab program:

clear
clc
% year number
year=input('Enter the year: ');
if mod(year,400)==0
    fprintf('\n%d is leap year',year);
elseif mod(year,100)==0
    fprintf('\n%d is not a leap year',year);
elseif mod(year,4)==0
    fprintf('\n%d is leap year',year);
else
    fprintf('\n%d is not a leap year',year);
end

Screenshot:

Save the above program and execute it and give the input.

Give the input year

Result:

Problem 2(a)

MatLab program:

clear
clc
% initially sum of series is zero
sum_series=0;
% k=1 to 10
% for loop
for k=1:10
    num=500+k*10+3;
    sum_series=sum_series+num;
end
fprintf('sum of series is %d',sum_series);

Screenshot:

Save the above program and execute it.

Result:

Problem 2(b)

MatLab program:

clear
clc
% k=1 to 10
k=1:10;
% without for loop
num=500+k*10+3;
sum_series=sum(num);
fprintf('sum of series is %d',sum_series);

Screenshot:

Save the above program and execute it.

Result:


Related Solutions

determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
For the following problems, use Octave/Matlab to determine whether the following sets
For the following problems, use Octave/Matlab to determine whether the following sets span \(\mathbb{R}^{3}\). Remember you need to pick an arbitrary element in \(\mathbb{R}^{3}\) and see if you can write it as a linear combination of the set of vectors.For each problem, do the following:1) - Write the row reduced echelon matrix found by Octave.2) - Tell me if this set spans \(\mathbb{R}^{3}\).3) - If this set spans \(\mathbb{R}^{3}\), solve for \(\alpha, \beta, \ldots\) (in other words, tell me how...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Develop three functions for temperature-conversion. Create a function called F_to_K that converts and return temperatures in Fahrenheit to Kelvin and store results in ‘F_to_K2.txt’. Create a function called C_to_R that converts and return temperatures in Celsius to Rankine and store results in ‘C_to_R2.txt’. Create a function called C_to_F that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT