Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB program in a script file that accepts a year and determines wheth

ID: 3688062 • Letter: W

Question

Write a MATLAB program in a script file that accepts a year and determines whether the year is a leap year. Use the mod function and an if-elseif-else construct with simple (i.e., not compound) conditions being checked. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are 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. Demonstrate the use of the program for the following years: 2015, 2016, and 2400. We are interested in determining the sum of the first N natural numbers where N is entered by the user. Write a MATLAB program in a script file to calculate the sum of the first N natural numbers. Use a loop to perform this calculation. Test your program with N = 100. Write a MATLAB program in a script file to calculate the sum of the first N natural numbers. Use vectorization to perform this calculation. Test your program with N = 50. A nonlinear function is given by f(x) = 2e^-x cos(x) + e^-2x cos(x/2). Write a user-defined MATLAB function that calculates f(x). For the function name and arguments use fx = func(x), where x is the input argument and f x represents the output argument. Write the function such that x can be a vector. Use the function to calculate f(1) and f(4). Use the function to make a plot of the function f(x) for 0 le x le 8 in 0.1 increments. Include a grid. A car that is 65 meters from the "finish line" is going 3 meters per second and accelerates

Explanation / Answer

1.
year = input('Enter an year: ');
if mod(year, 400) == 0
disp('Leap year');
elseif mod(year, 4) == 0 && mod(year, 100) != 0
disp('Leap year');
else
disp('Not leap year');
end


2.
(a)
N = 100;
sum = 0;
for i = 1:N
sum = sum + i;
end
disp(sum);

(b)
N = 100;
sum = zeros(N);
sum(1) = 1;
for i = 2:N
sum(i) = sum(i - 1) + i;
end
disp(sum(100));

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote